Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit e92dfcf

Browse files
committed
Fix common asserts in animation API.
1. We would assert if you tried to start an animation from within an animation status callback. This is a common pattern, so I fixed this assert (in Ticker._tick). 2. We would assert for animations with duration under a millisecond. Fixed. Also removed the workarounds assocated with #1.
1 parent 8af8d68 commit e92dfcf

File tree

5 files changed

+12
-22
lines changed

5 files changed

+12
-22
lines changed

sky/packages/sky/lib/animation/animated_simulation.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ class Ticker {
5151

5252
_onTick(timeStamp);
5353

54-
if (isTicking)
54+
// The onTick callback may have scheduled another tick already.
55+
if (isTicking && _animationId == null)
5556
_scheduleTick();
5657
}
5758

sky/packages/sky/lib/animation/timeline.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class TweenSimulation extends Simulation {
1414
final double end;
1515

1616
TweenSimulation(Duration duration, this.begin, this.end) :
17-
_durationInSeconds = duration.inMilliseconds / 1000.0 {
17+
_durationInSeconds = duration.inMicroseconds / Duration.MICROSECONDS_PER_SECOND {
1818
assert(_durationInSeconds > 0.0);
1919
assert(begin != null && begin >= 0.0 && begin <= 1.0);
2020
assert(end != null && end >= 0.0 && end <= 1.0);

sky/packages/sky/lib/widgets/drawer.dart

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import 'dart:async';
65
import 'dart:sky' as sky;
76

87
import 'package:sky/animation/animated_value.dart';
@@ -69,9 +68,7 @@ class Drawer extends StatefulComponent {
6968
_performance.attachedForce = kDefaultSpringForce;
7069

7170
if (navigator != null) {
72-
scheduleMicrotask(() {
73-
navigator.pushState(this, (_) => _performance.reverse());
74-
});
71+
navigator.pushState(this, (_) => _performance.reverse());
7572
}
7673
}
7774

@@ -120,14 +117,12 @@ class Drawer extends StatefulComponent {
120117
}
121118

122119
void _onDismissed() {
123-
scheduleMicrotask(() {
124-
if (navigator != null &&
125-
navigator.currentRoute is RouteState &&
126-
(navigator.currentRoute as RouteState).owner == this) // TODO(ianh): remove cast once analyzer is cleverer
127-
navigator.pop();
128-
if (onDismissed != null)
129-
onDismissed();
130-
});
120+
if (navigator != null &&
121+
navigator.currentRoute is RouteState &&
122+
(navigator.currentRoute as RouteState).owner == this) // TODO(ianh): remove cast once analyzer is cleverer
123+
navigator.pop();
124+
if (onDismissed != null)
125+
onDismissed();
131126
}
132127

133128
bool get _isMostlyClosed => _performance.progress < 0.5;

sky/packages/sky/lib/widgets/popup_menu.dart

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import 'dart:async';
65
import 'dart:sky' as sky;
76

87
import 'package:sky/animation/animated_value.dart';
@@ -72,11 +71,7 @@ class PopupMenu extends StatefulComponent {
7271
}
7372

7473
void _open() {
75-
if (navigator != null) {
76-
scheduleMicrotask(() {
77-
navigator.pushState(this, (_) => _close());
78-
});
79-
}
74+
navigator.pushState(this, (_) => _close());
8075
}
8176

8277
void _close() {

sky/packages/sky/lib/widgets/snack_bar.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import 'dart:async';
65

76
import 'package:sky/animation/animated_value.dart';
87
import 'package:sky/animation/animation_performance.dart';
@@ -61,7 +60,7 @@ class SnackBar extends Component {
6160

6261
void _onDismissed() {
6362
if (onDismissed != null)
64-
scheduleMicrotask(() { onDismissed(); });
63+
onDismissed();
6564
}
6665

6766
Widget build() {

0 commit comments

Comments
 (0)