diff --git a/examples/material_gallery/lib/demo/page_selector_demo.dart b/examples/material_gallery/lib/demo/page_selector_demo.dart index 594724bcb0..3df5c1c99d 100644 --- a/examples/material_gallery/lib/demo/page_selector_demo.dart +++ b/examples/material_gallery/lib/demo/page_selector_demo.dart @@ -18,7 +18,7 @@ class PageSelectorDemo extends StatelessComponent { builder: (BuildContext context, Widget child) { Color background = selection.value == iconName ? _selectedColor.end : _selectedColor.begin; if (selection.valueIsChanging) { - // Then the selection's performance is animating from previousValue to value. + // Then the selection's animation is animating from previousValue to value. if (selection.value == iconName) background = _selectedColor.evaluate(animation); else if (selection.previousValue == iconName) diff --git a/packages/flutter/lib/src/animation/animations.dart b/packages/flutter/lib/src/animation/animations.dart index fcf42956bc..a969d6db24 100644 --- a/packages/flutter/lib/src/animation/animations.dart +++ b/packages/flutter/lib/src/animation/animations.dart @@ -11,7 +11,6 @@ import 'tween.dart'; class AlwaysCompleteAnimation extends Animated { const AlwaysCompleteAnimation(); - // this performance never changes state void addListener(VoidCallback listener) { } void removeListener(VoidCallback listener) { } void addStatusListener(PerformanceStatusListener listener) { } @@ -26,7 +25,6 @@ const AlwaysCompleteAnimation kAlwaysCompleteAnimation = const AlwaysCompleteAni class AlwaysDismissedAnimation extends Animated { const AlwaysDismissedAnimation(); - // this performance never changes state void addListener(VoidCallback listener) { } void removeListener(VoidCallback listener) { } void addStatusListener(PerformanceStatusListener listener) { } diff --git a/packages/flutter/lib/src/animation/simulation_stepper.dart b/packages/flutter/lib/src/animation/simulation_stepper.dart index e0a2902286..caeefc12e2 100644 --- a/packages/flutter/lib/src/animation/simulation_stepper.dart +++ b/packages/flutter/lib/src/animation/simulation_stepper.dart @@ -5,31 +5,32 @@ import 'dart:async'; import 'package:newton/newton.dart'; -import 'animated_value.dart'; import 'curves.dart'; import 'ticker.dart'; -/// A simulation that varies from [begin] to [end] over [duration] using [curve]. -/// -/// This class is an adaptor between the Simulation interface and the -/// AnimatedValue interface. +/// A simulation that varies from begin to end over duration using curve. class _TweenSimulation extends Simulation { - _TweenSimulation(double begin, double end, Duration duration, Curve curve) - : _durationInSeconds = duration.inMicroseconds / Duration.MICROSECONDS_PER_SECOND, - _tween = new AnimatedValue(begin, end: end, curve: curve) { + _TweenSimulation(this._begin, this._end, Duration duration, this._curve) + : _durationInSeconds = duration.inMicroseconds / Duration.MICROSECONDS_PER_SECOND { assert(_durationInSeconds > 0.0); - assert(begin != null); - assert(end != null); + assert(_begin != null); + assert(_end != null); } final double _durationInSeconds; - final AnimatedValue _tween; + final double _begin; + final double _end; + final Curve _curve; double x(double timeInSeconds) { assert(timeInSeconds >= 0.0); - final double t = (timeInSeconds / _durationInSeconds).clamp(0.0, 1.0); - _tween.setProgress(t, AnimationDirection.forward); - return _tween.value; + double t = (timeInSeconds / _durationInSeconds).clamp(0.0, 1.0); + if (t == 0.0) + return _begin; + else if (t == 1.0) + return _end; + else + return _begin + (_end - _begin) * _curve.transform(t); } double dx(double timeInSeconds) => 1.0; diff --git a/packages/flutter/lib/src/animation/tween.dart b/packages/flutter/lib/src/animation/tween.dart index f70e2e0acd..b512ee8463 100644 --- a/packages/flutter/lib/src/animation/tween.dart +++ b/packages/flutter/lib/src/animation/tween.dart @@ -100,6 +100,10 @@ abstract class Evaluatable { Animated animate(Animated parent) { return new _AnimatedEvaluation(parent, this); } + + Evaluatable chain(Evaluatable parent) { + return new _ChainedEvaluation(parent, this); + } } class _AnimatedEvaluation extends Animated with ProxyAnimatedMixin { @@ -113,6 +117,31 @@ class _AnimatedEvaluation extends Animated with ProxyAnimatedMixin { T get value => _evaluatable.evaluate(parent); } +class AlwaysStoppedAnimation extends Animated { + const AlwaysStoppedAnimation(this.value); + + final double value; + + void addListener(VoidCallback listener) { } + void removeListener(VoidCallback listener) { } + void addStatusListener(PerformanceStatusListener listener) { } + void removeStatusListener(PerformanceStatusListener listener) { } + PerformanceStatus get status => PerformanceStatus.forward; + AnimationDirection get direction => AnimationDirection.forward; +} + +class _ChainedEvaluation extends Evaluatable { + _ChainedEvaluation(this._parent, this._evaluatable); + + final Evaluatable _parent; + final Evaluatable _evaluatable; + + T evaluate(Animated animation) { + double value = _parent.evaluate(animation); + return _evaluatable.evaluate(new AlwaysStoppedAnimation(value)); + } +} + class AnimationController extends Animated with EagerListenerMixin, LocalPerformanceListenersMixin, LocalPerformanceStatusListenersMixin { AnimationController({ this.duration, double value, this.debugLabel }) { diff --git a/packages/flutter/lib/src/rendering/box.dart b/packages/flutter/lib/src/rendering/box.dart index fcabc79b95..f01030f3cf 100644 --- a/packages/flutter/lib/src/rendering/box.dart +++ b/packages/flutter/lib/src/rendering/box.dart @@ -854,9 +854,8 @@ abstract class RenderBoxContainerDefaultsMixin { - AnimatedFractionalOffsetValue(FractionalOffset begin, { FractionalOffset end, Curve curve, Curve reverseCurve }) - : super(begin, end: end, curve: curve, reverseCurve: reverseCurve); +class FractionalOffsetTween extends Tween { + FractionalOffsetTween({ FractionalOffset begin, FractionalOffset end }) : super(begin: begin, end: end); FractionalOffset lerp(double t) => FractionalOffset.lerp(begin, end, t); } diff --git a/packages/flutter/lib/src/widgets/enter_exit_transition.dart b/packages/flutter/lib/src/widgets/enter_exit_transition.dart index e7c4b0b232..1ba2438bdf 100644 --- a/packages/flutter/lib/src/widgets/enter_exit_transition.dart +++ b/packages/flutter/lib/src/widgets/enter_exit_transition.dart @@ -30,32 +30,41 @@ class SmoothlyResizingOverflowBox extends StatefulComponent { } class _SmoothlyResizingOverflowBoxState extends State { - ValuePerformance _size; + SizeTween _sizeTween; + CurveTween _curveTween; + Animated _size; + AnimationController _sizeController; void initState() { super.initState(); - _size = new ValuePerformance( - variable: new AnimatedSizeValue(config.size, curve: config.curve), - duration: config.duration - )..addListener(() { - setState(() {}); - }); + _sizeController = new AnimationController(duration: config.duration); + _sizeTween = new SizeTween(begin: config.size); + _curveTween = new CurveTween(curve: config.curve); + _size = _sizeTween.chain(_curveTween).animate(_sizeController) + ..addListener(() { + setState(() {}); + }); } void didUpdateConfig(SmoothlyResizingOverflowBox oldConfig) { - _size.duration = config.duration; - _size.variable.curve = config.curve; + bool needsAnimation = false; if (config.size != oldConfig.size) { - AnimatedSizeValue variable = _size.variable; - variable.begin = variable.value; - variable.end = config.size; - _size.progress = 0.0; - _size.play(); + _sizeTween + ..begin = _size.value + ..end = config.size; + needsAnimation = true; + } + _sizeController.duration = config.duration; + _curveTween.curve = config.curve; + if (needsAnimation) { + _sizeController + ..value = 0.0 + ..forward(); } } void dispose() { - _size.stop(); + _sizeController.stop(); super.dispose(); } diff --git a/packages/flutter/lib/src/widgets/transitions.dart b/packages/flutter/lib/src/widgets/transitions.dart index 78bd6b5c85..fc174ab8d3 100644 --- a/packages/flutter/lib/src/widgets/transitions.dart +++ b/packages/flutter/lib/src/widgets/transitions.dart @@ -193,24 +193,6 @@ class RotationTransition extends AnimatedComponent { } } -class OldFadeTransition extends TransitionWithChild { - OldFadeTransition({ - Key key, - this.opacity, - PerformanceView performance, - Widget child - }) : super(key: key, - performance: performance, - child: child); - - final AnimatedValue opacity; - - Widget buildWithChild(BuildContext context, Widget child) { - performance.updateVariable(opacity); - return new Opacity(opacity: opacity.value, child: child); - } -} - class FadeTransition extends AnimatedComponent { FadeTransition({ Key key, @@ -226,20 +208,17 @@ class FadeTransition extends AnimatedComponent { } } -class ColorTransition extends TransitionWithChild { +class ColorTransition extends AnimatedComponent { ColorTransition({ Key key, - this.color, - PerformanceView performance, - Widget child - }) : super(key: key, - performance: performance, - child: child); + Animated color, + this.child + }) : color = color, super(key: key, animation: color); - final AnimatedColorValue color; + final Animated color; + final Widget child; - Widget buildWithChild(BuildContext context, Widget child) { - performance.updateVariable(color); + Widget build(BuildContext context) { return new DecoratedBox( decoration: new BoxDecoration(backgroundColor: color.value), child: child