Skip to content

Commit

Permalink
Merge pull request flutter#592 from mpcomplete/animation.asserts
Browse files Browse the repository at this point in the history
Fix common asserts in animation API.
  • Loading branch information
mpcomplete committed Aug 13, 2015
2 parents 9caa051 + e92dfcf commit 761fd54
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 22 deletions.
3 changes: 2 additions & 1 deletion sky/packages/sky/lib/animation/animated_simulation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class Ticker {

_onTick(timeStamp);

if (isTicking)
// The onTick callback may have scheduled another tick already.
if (isTicking && _animationId == null)
_scheduleTick();
}

Expand Down
2 changes: 1 addition & 1 deletion sky/packages/sky/lib/animation/timeline.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class TweenSimulation extends Simulation {
final double end;

TweenSimulation(Duration duration, this.begin, this.end) :
_durationInSeconds = duration.inMilliseconds / 1000.0 {
_durationInSeconds = duration.inMicroseconds / Duration.MICROSECONDS_PER_SECOND {
assert(_durationInSeconds > 0.0);
assert(begin != null && begin >= 0.0 && begin <= 1.0);
assert(end != null && end >= 0.0 && end <= 1.0);
Expand Down
19 changes: 7 additions & 12 deletions sky/packages/sky/lib/widgets/drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';
import 'dart:sky' as sky;

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

if (navigator != null) {
scheduleMicrotask(() {
navigator.pushState(this, (_) => _performance.reverse());
});
navigator.pushState(this, (_) => _performance.reverse());
}
}

Expand Down Expand Up @@ -120,14 +117,12 @@ class Drawer extends StatefulComponent {
}

void _onDismissed() {
scheduleMicrotask(() {
if (navigator != null &&
navigator.currentRoute is RouteState &&
(navigator.currentRoute as RouteState).owner == this) // TODO(ianh): remove cast once analyzer is cleverer
navigator.pop();
if (onDismissed != null)
onDismissed();
});
if (navigator != null &&
navigator.currentRoute is RouteState &&
(navigator.currentRoute as RouteState).owner == this) // TODO(ianh): remove cast once analyzer is cleverer
navigator.pop();
if (onDismissed != null)
onDismissed();
}

bool get _isMostlyClosed => _performance.progress < 0.5;
Expand Down
7 changes: 1 addition & 6 deletions sky/packages/sky/lib/widgets/popup_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';
import 'dart:sky' as sky;

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

void _open() {
if (navigator != null) {
scheduleMicrotask(() {
navigator.pushState(this, (_) => _close());
});
}
navigator.pushState(this, (_) => _close());
}

void _close() {
Expand Down
3 changes: 1 addition & 2 deletions sky/packages/sky/lib/widgets/snack_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';

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

void _onDismissed() {
if (onDismissed != null)
scheduleMicrotask(() { onDismissed(); });
onDismissed();
}

Widget build() {
Expand Down

0 comments on commit 761fd54

Please sign in to comment.