From 7b0e7ee38e379b15014831741b00a084f887dfcf Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Mon, 22 Feb 2016 14:18:17 -0800 Subject: [PATCH] Some trivial animation library cleanup. --- .../src/animation/animation_controller.dart | 86 +++++++++---------- .../flutter/lib/src/animation/animations.dart | 4 +- packages/flutter/lib/src/animation/tween.dart | 2 +- 3 files changed, 46 insertions(+), 46 deletions(-) diff --git a/packages/flutter/lib/src/animation/animation_controller.dart b/packages/flutter/lib/src/animation/animation_controller.dart index b6846a9aa64..e0aee1c9783 100644 --- a/packages/flutter/lib/src/animation/animation_controller.dart +++ b/packages/flutter/lib/src/animation/animation_controller.dart @@ -48,7 +48,7 @@ class AnimationController extends Animation /// * debugLabel is a string to help identify this animation during debugging (used by toString). /// /// This constructor is most useful for animations that will be driven using a - /// physics simulation, especially when the physics simulation as no + /// physics simulation, especially when the physics simulation has no /// pre-determined bounds. AnimationController.unbounded({ double value: 0.0, @@ -128,48 +128,6 @@ class AnimationController extends Animation return animateTo(_direction == AnimationDirection.forward ? upperBound : lowerBound); } - /// Stops running this animation. - void stop() { - _simulation = null; - _ticker.stop(); - } - - /// Stops running this animation. - void dispose() { - stop(); - } - - /// Flings the timeline with an optional force (defaults to a critically - /// damped spring) and initial velocity. If velocity is positive, the - /// animation will complete, otherwise it will dismiss. - Future fling({ double velocity: 1.0, Force force }) { - force ??= kDefaultSpringForce; - _direction = velocity < 0.0 ? AnimationDirection.reverse : AnimationDirection.forward; - return animateWith(force.release(value, velocity)); - } - - /// Starts running this animation in the forward direction, and - /// restarts the animation when it completes. - Future repeat({ double min: 0.0, double max: 1.0, Duration period }) { - period ??= duration; - return animateWith(new _RepeatingSimulation(min, max, period)); - } - - /// Drives the animation according to the given simulation. - Future animateWith(Simulation simulation) { - stop(); - return _startSimulation(simulation); - } - - AnimationStatus _lastStatus = AnimationStatus.dismissed; - void _checkStatusChanged() { - AnimationStatus newStatus = status; - AnimationStatus oldStatus = _lastStatus; - _lastStatus = newStatus; - if (oldStatus != newStatus) - notifyStatusListeners(newStatus); - } - /// Drives the animation from its current value to target. Future animateTo(double target, { Duration duration, Curve curve: Curves.linear }) { Duration simulationDuration = duration; @@ -190,6 +148,28 @@ class AnimationController extends Animation return _startSimulation(new _TweenSimulation(_value, target, simulationDuration, curve)); } + /// Starts running this animation in the forward direction, and + /// restarts the animation when it completes. + Future repeat({ double min: 0.0, double max: 1.0, Duration period }) { + period ??= duration; + return animateWith(new _RepeatingSimulation(min, max, period)); + } + + /// Flings the timeline with an optional force (defaults to a critically + /// damped spring) and initial velocity. If velocity is positive, the + /// animation will complete, otherwise it will dismiss. + Future fling({ double velocity: 1.0, Force force }) { + force ??= kDefaultSpringForce; + _direction = velocity < 0.0 ? AnimationDirection.reverse : AnimationDirection.forward; + return animateWith(force.release(value, velocity)); + } + + /// Drives the animation according to the given simulation. + Future animateWith(Simulation simulation) { + stop(); + return _startSimulation(simulation); + } + Future _startSimulation(Simulation simulation) { assert(simulation != null); assert(!isAnimating); @@ -198,6 +178,26 @@ class AnimationController extends Animation return _ticker.start(); } + /// Stops running this animation. + void stop() { + _simulation = null; + _ticker.stop(); + } + + /// Stops running this animation. + void dispose() { + stop(); + } + + AnimationStatus _lastStatus = AnimationStatus.dismissed; + void _checkStatusChanged() { + AnimationStatus newStatus = status; + AnimationStatus oldStatus = _lastStatus; + _lastStatus = newStatus; + if (oldStatus != newStatus) + notifyStatusListeners(newStatus); + } + void _tick(Duration elapsed) { double elapsedInSeconds = elapsed.inMicroseconds.toDouble() / Duration.MICROSECONDS_PER_SECOND; _value = _simulation.x(elapsedInSeconds); diff --git a/packages/flutter/lib/src/animation/animations.dart b/packages/flutter/lib/src/animation/animations.dart index 831948d94ab..08e269eb687 100644 --- a/packages/flutter/lib/src/animation/animations.dart +++ b/packages/flutter/lib/src/animation/animations.dart @@ -47,10 +47,10 @@ class _AlwaysDismissedAnimation extends Animation { const Animation kAlwaysDismissedAnimation = const _AlwaysDismissedAnimation(); /// An animation that is always stopped at a given value. -class AlwaysStoppedAnimation extends Animation { +class AlwaysStoppedAnimation extends Animation { const AlwaysStoppedAnimation(this.value); - final double value; + final T value; void addListener(VoidCallback listener) { } void removeListener(VoidCallback listener) { } diff --git a/packages/flutter/lib/src/animation/tween.dart b/packages/flutter/lib/src/animation/tween.dart index cdea0af1219..65991caeaa1 100644 --- a/packages/flutter/lib/src/animation/tween.dart +++ b/packages/flutter/lib/src/animation/tween.dart @@ -47,7 +47,7 @@ class _ChainedEvaluation extends Animatable { T evaluate(Animation animation) { double value = _parent.evaluate(animation); - return _evaluatable.evaluate(new AlwaysStoppedAnimation(value)); + return _evaluatable.evaluate(new AlwaysStoppedAnimation(value)); } }