Commit 3f8fdb66 authored by Ian Hickson's avatar Ian Hickson

Merge pull request #2098 from Hixie/animation-cleanup

Some trivial animation library cleanup.
parents 67ea03c7 7b0e7ee3
......@@ -48,7 +48,7 @@ class AnimationController extends Animation<double>
/// * 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<double>
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<double>
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<double>
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);
......
......@@ -47,10 +47,10 @@ class _AlwaysDismissedAnimation extends Animation<double> {
const Animation<double> kAlwaysDismissedAnimation = const _AlwaysDismissedAnimation();
/// An animation that is always stopped at a given value.
class AlwaysStoppedAnimation extends Animation<double> {
class AlwaysStoppedAnimation<T> extends Animation<T> {
const AlwaysStoppedAnimation(this.value);
final double value;
final T value;
void addListener(VoidCallback listener) { }
void removeListener(VoidCallback listener) { }
......
......@@ -47,7 +47,7 @@ class _ChainedEvaluation<T> extends Animatable<T> {
T evaluate(Animation<double> animation) {
double value = _parent.evaluate(animation);
return _evaluatable.evaluate(new AlwaysStoppedAnimation(value));
return _evaluatable.evaluate(new AlwaysStoppedAnimation<double>(value));
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment