From f79fdff2d0181c767dda457d982823286e72429c Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Mon, 19 Oct 2015 18:08:52 -0700 Subject: [PATCH] Move animation curves into a Curves namespace --- examples/game/test_physics.dart | 8 +-- examples/widgets/progress_indicator.dart | 4 +- .../flutter/lib/src/animation/curves.dart | 55 ++++++++++--------- .../lib/src/animation/simulation_stepper.dart | 2 +- packages/flutter/lib/src/material/dialog.dart | 2 +- packages/flutter/lib/src/material/drawer.dart | 2 +- .../flutter/lib/src/material/ink_well.dart | 2 +- .../flutter/lib/src/material/material.dart | 2 +- .../lib/src/material/progress_indicator.dart | 2 +- .../lib/src/material/radial_reaction.dart | 8 +-- .../lib/src/material/scrollbar_painter.dart | 2 +- .../flutter/lib/src/material/snack_bar.dart | 4 +- packages/flutter/lib/src/material/tabs.dart | 2 +- .../flutter/lib/src/rendering/toggleable.dart | 2 +- .../lib/src/widgets/animated_container.dart | 2 +- .../flutter/lib/src/widgets/dismissable.dart | 2 +- .../flutter/lib/src/widgets/navigator.dart | 4 +- .../flutter/lib/src/widgets/scrollable.dart | 4 +- .../unit/test/widget/positioned_test.dart | 2 +- 19 files changed, 58 insertions(+), 53 deletions(-) diff --git a/examples/game/test_physics.dart b/examples/game/test_physics.dart index b645d365160..5c22c30fa76 100644 --- a/examples/game/test_physics.dart +++ b/examples/game/test_physics.dart @@ -67,14 +67,14 @@ class TestBed extends NodeWithSize { // Animate obstacle ActionSequence seq = new ActionSequence([ - new ActionTween((a) => _obstacle.position = a, new Point(256.0, 800.0), new Point(768.0, 800.0), 1.0, easeInOut), - new ActionTween((a) => _obstacle.position = a, new Point(768.0, 800.0), new Point(256.0, 800.0), 1.0, easeInOut) + new ActionTween((a) => _obstacle.position = a, new Point(256.0, 800.0), new Point(768.0, 800.0), 1.0, Curves.easeInOut), + new ActionTween((a) => _obstacle.position = a, new Point(768.0, 800.0), new Point(256.0, 800.0), 1.0, Curves.easeInOut) ]); _obstacle.actions.run(new ActionRepeatForever(seq)); seq = new ActionSequence([ - new ActionTween((a) => _obstacle.scale = a, 1.0, 2.0, 2.0, easeInOut), - new ActionTween((a) => _obstacle.scale = a, 2.0, 1.0, 2.0, easeInOut) + new ActionTween((a) => _obstacle.scale = a, 1.0, 2.0, 2.0, Curves.easeInOut), + new ActionTween((a) => _obstacle.scale = a, 2.0, 1.0, 2.0, Curves.easeInOut) ]); _obstacle.actions.run(new ActionRepeatForever(seq)); diff --git a/examples/widgets/progress_indicator.dart b/examples/widgets/progress_indicator.dart index 392d52afd01..b28f6cb6741 100644 --- a/examples/widgets/progress_indicator.dart +++ b/examples/widgets/progress_indicator.dart @@ -17,8 +17,8 @@ class ProgressIndicatorAppState extends State { ..variable = new AnimatedValue( 0.0, end: 1.0, - curve: new Interval(0.0, 0.9, curve: ease), - reverseCurve: ease + curve: new Interval(0.0, 0.9, curve: Curves.ease), + reverseCurve: Curves.ease ); valueAnimation.addStatusListener((PerformanceStatus status) { if (status == PerformanceStatus.dismissed || status == PerformanceStatus.completed) diff --git a/packages/flutter/lib/src/animation/curves.dart b/packages/flutter/lib/src/animation/curves.dart index 5b44cc43ebe..3d0f6f57027 100644 --- a/packages/flutter/lib/src/animation/curves.dart +++ b/packages/flutter/lib/src/animation/curves.dart @@ -29,7 +29,7 @@ class Linear implements Curve { /// A curve that is 0.0 until start, then curved from 0.0 to 1.0 at end, then 1.0 class Interval implements Curve { - const Interval(this.start, this.end, { this.curve: linear }); + const Interval(this.start, this.end, { this.curve: Curves.linear }); /// The smallest value for which this interval is 0.0 final double start; @@ -153,38 +153,43 @@ class ElasticInOutCurve implements Curve { } } -/// A linear animation curve -const Linear linear = const Linear(); +/// A collection of common animation curves. +class Curves { + Curves._(); -/// A cubic animation curve that speeds up quickly and ends slowly -const Cubic ease = const Cubic(0.25, 0.1, 0.25, 1.0); + /// A linear animation curve + static const Linear linear = const Linear(); -/// A cubic animation curve that starts slowly and ends quickly -const Cubic easeIn = const Cubic(0.42, 0.0, 1.0, 1.0); + /// A cubic animation curve that speeds up quickly and ends slowly + static const Cubic ease = const Cubic(0.25, 0.1, 0.25, 1.0); -/// A cubic animation curve that starts quickly and ends slowly -const Cubic easeOut = const Cubic(0.0, 0.0, 0.58, 1.0); + /// A cubic animation curve that starts slowly and ends quickly + static const Cubic easeIn = const Cubic(0.42, 0.0, 1.0, 1.0); -/// A cubic animation curve that starts slowly, speeds up, and then and ends slowly -const Cubic easeInOut = const Cubic(0.42, 0.0, 0.58, 1.0); + /// A cubic animation curve that starts quickly and ends slowly + static const Cubic easeOut = const Cubic(0.0, 0.0, 0.58, 1.0); -/// An oscillating curve that grows in magnitude -const BounceInCurve bounceIn = const BounceInCurve(); + /// A cubic animation curve that starts slowly, speeds up, and then and ends slowly + static const Cubic easeInOut = const Cubic(0.42, 0.0, 0.58, 1.0); -/// An oscillating curve that first grows and then shrink in magnitude -const BounceOutCurve bounceOut = const BounceOutCurve(); + /// An oscillating curve that grows in magnitude + static const BounceInCurve bounceIn = const BounceInCurve(); -/// An oscillating curve that first grows and then shrink in magnitude -const BounceInOutCurve bounceInOut = const BounceInOutCurve(); + /// An oscillating curve that first grows and then shrink in magnitude + static const BounceOutCurve bounceOut = const BounceOutCurve(); -/// An oscillating curve that grows in magnitude while overshootings its bounds -const ElasticInCurve elasticIn = const ElasticInCurve(); + /// An oscillating curve that first grows and then shrink in magnitude + static const BounceInOutCurve bounceInOut = const BounceInOutCurve(); -/// An oscillating curve that shrinks in magnitude while overshootings its bounds -const ElasticOutCurve elasticOut = const ElasticOutCurve(); + /// An oscillating curve that grows in magnitude while overshootings its bounds + static const ElasticInCurve elasticIn = const ElasticInCurve(); -/// An oscillating curve that grows and then shrinks in magnitude while overshootings its bounds -const ElasticInOutCurve elasticInOut = const ElasticInOutCurve(); + /// An oscillating curve that shrinks in magnitude while overshootings its bounds + static const ElasticOutCurve elasticOut = const ElasticOutCurve(); -/// A curve that starts quickly and eases into its final position. Over the course of the animation, the object spends more time near its final destination. As a result, the user isn’t left waiting for the animation to finish, and the negative effects of motion are minimized. -const Curve fastOutSlowIn = const Cubic(0.4, 0.0, 0.2, 1.0); + /// An oscillating curve that grows and then shrinks in magnitude while overshootings its bounds + static const ElasticInOutCurve elasticInOut = const ElasticInOutCurve(); + + /// A curve that starts quickly and eases into its final position. Over the course of the animation, the object spends more time near its final destination. As a result, the user isn’t left waiting for the animation to finish, and the negative effects of motion are minimized. + static const Curve fastOutSlowIn = const Cubic(0.4, 0.0, 0.2, 1.0); +} diff --git a/packages/flutter/lib/src/animation/simulation_stepper.dart b/packages/flutter/lib/src/animation/simulation_stepper.dart index 843be0a0620..44d6a6acfd5 100644 --- a/packages/flutter/lib/src/animation/simulation_stepper.dart +++ b/packages/flutter/lib/src/animation/simulation_stepper.dart @@ -66,7 +66,7 @@ class SimulationStepper { /// /// Returns a future that resolves when the timeline stops animating, /// typically when the timeline arives at the target value. - Future animateTo(double target, { Duration duration, Curve curve: linear }) { + Future animateTo(double target, { Duration duration, Curve curve: Curves.linear }) { assert(duration > Duration.ZERO); assert(!isAnimating); return _start(new _TweenSimulation(value, target, duration, curve)); diff --git a/packages/flutter/lib/src/material/dialog.dart b/packages/flutter/lib/src/material/dialog.dart index 6bf57bab001..bb6157919f3 100644 --- a/packages/flutter/lib/src/material/dialog.dart +++ b/packages/flutter/lib/src/material/dialog.dart @@ -142,7 +142,7 @@ class _DialogRoute extends PerformanceRoute { Widget build(NavigatorState navigator, PerformanceView nextRoutePerformance) { return new FadeTransition( performance: performance, - opacity: new AnimatedValue(0.0, end: 1.0, curve: easeOut), + opacity: new AnimatedValue(0.0, end: 1.0, curve: Curves.easeOut), child: builder(new RouteArguments(navigator: navigator, previousPerformance: this.performance, nextPerformance: nextRoutePerformance)) ); } diff --git a/packages/flutter/lib/src/material/drawer.dart b/packages/flutter/lib/src/material/drawer.dart index 35ea2ef5967..d0dcdcb3388 100644 --- a/packages/flutter/lib/src/material/drawer.dart +++ b/packages/flutter/lib/src/material/drawer.dart @@ -83,7 +83,7 @@ class _Drawer extends StatelessComponent { performance: performance, position: new AnimatedValue(_kClosedPosition, end: _kOpenPosition), child: new AnimatedContainer( - curve: ease, + curve: Curves.ease, duration: _kThemeChangeDuration, decoration: new BoxDecoration( backgroundColor: Theme.of(context).canvasColor, diff --git a/packages/flutter/lib/src/material/ink_well.dart b/packages/flutter/lib/src/material/ink_well.dart index bc4bb235b01..0d5ca2d47b3 100644 --- a/packages/flutter/lib/src/material/ink_well.dart +++ b/packages/flutter/lib/src/material/ink_well.dart @@ -28,7 +28,7 @@ class _InkSplash { _InkSplash(this.position, this.well) { _targetRadius = _getSplashTargetSize(well.size, position); _radius = new AnimatedValue( - _kSplashInitialSize, end: _targetRadius, curve: easeOut); + _kSplashInitialSize, end: _targetRadius, curve: Curves.easeOut); _performance = new ValuePerformance( variable: _radius, diff --git a/packages/flutter/lib/src/material/material.dart b/packages/flutter/lib/src/material/material.dart index 893d4788d4f..96ada6ff6e2 100644 --- a/packages/flutter/lib/src/material/material.dart +++ b/packages/flutter/lib/src/material/material.dart @@ -67,7 +67,7 @@ class Material extends StatelessComponent { return new DefaultTextStyle( style: Theme.of(context).text.body1, child: new AnimatedContainer( - curve: ease, + curve: Curves.ease, duration: kThemeChangeDuration, decoration: new BoxDecoration( backgroundColor: _getBackgroundColor(context), diff --git a/packages/flutter/lib/src/material/progress_indicator.dart b/packages/flutter/lib/src/material/progress_indicator.dart index 1fd6a7190ec..ac41cf20666 100644 --- a/packages/flutter/lib/src/material/progress_indicator.dart +++ b/packages/flutter/lib/src/material/progress_indicator.dart @@ -45,7 +45,7 @@ class _ProgressIndicatorState extends State { void initState() { super.initState(); _performance = new ValuePerformance( - variable: new AnimatedValue(0.0, end: 1.0, curve: ease), + variable: new AnimatedValue(0.0, end: 1.0, curve: Curves.ease), duration: const Duration(milliseconds: 1500) ); _performance.addStatusListener((PerformanceStatus status) { diff --git a/packages/flutter/lib/src/material/radial_reaction.dart b/packages/flutter/lib/src/material/radial_reaction.dart index 8e7349673ca..7d550b6885f 100644 --- a/packages/flutter/lib/src/material/radial_reaction.dart +++ b/packages/flutter/lib/src/material/radial_reaction.dart @@ -26,9 +26,9 @@ class RadialReaction { this.radius, Point startPosition }) { - _outerOpacity = new AnimatedValue(0.0, end: _kMaxOpacity, curve: easeOut); - _innerCenter = new AnimatedValue(startPosition, end: center, curve: easeOut); - _innerRadius = new AnimatedValue(0.0, end: radius, curve: easeOut); + _outerOpacity = new AnimatedValue(0.0, end: _kMaxOpacity, curve: Curves.easeOut); + _innerCenter = new AnimatedValue(startPosition, end: center, curve: Curves.easeOut); + _innerRadius = new AnimatedValue(0.0, end: radius, curve: Curves.easeOut); _showPerformance = new Performance(duration: _kShowDuration) ..addListener(() { _showPerformance.updateVariable(_outerOpacity); @@ -36,7 +36,7 @@ class RadialReaction { _showPerformance.updateVariable(_innerRadius); }); _fade = new ValuePerformance( - variable: new AnimatedValue(1.0, end: 0.0, curve: easeIn), + variable: new AnimatedValue(1.0, end: 0.0, curve: Curves.easeIn), duration: _kHideDuration ); } diff --git a/packages/flutter/lib/src/material/scrollbar_painter.dart b/packages/flutter/lib/src/material/scrollbar_painter.dart index cd839f43f0d..5eb8f72ef04 100644 --- a/packages/flutter/lib/src/material/scrollbar_painter.dart +++ b/packages/flutter/lib/src/material/scrollbar_painter.dart @@ -62,7 +62,7 @@ class ScrollbarPainter extends ScrollableListPainter { Future scrollStarted() { _fade ??= new ValuePerformance() ..duration = _kScrollbarThumbFadeDuration - ..variable = new AnimatedValue(0.0, end: 1.0, curve: ease) + ..variable = new AnimatedValue(0.0, end: 1.0, curve: Curves.ease) ..addListener(() { _opacity = _fade.value; renderer?.markNeedsPaint(); diff --git a/packages/flutter/lib/src/material/snack_bar.dart b/packages/flutter/lib/src/material/snack_bar.dart index 8ec933a93b4..340174daa05 100644 --- a/packages/flutter/lib/src/material/snack_bar.dart +++ b/packages/flutter/lib/src/material/snack_bar.dart @@ -67,8 +67,8 @@ class SnackBar extends StatelessComponent { height: new AnimatedValue( 0.0, end: kSnackBarHeight, - curve: easeIn, - reverseCurve: easeOut + curve: Curves.easeIn, + reverseCurve: Curves.easeOut ), child: new ClipRect( child: new OverflowBox( diff --git a/packages/flutter/lib/src/material/tabs.dart b/packages/flutter/lib/src/material/tabs.dart index dcb917446bf..da976a08fa4 100644 --- a/packages/flutter/lib/src/material/tabs.dart +++ b/packages/flutter/lib/src/material/tabs.dart @@ -404,7 +404,7 @@ class _TabBarState extends ScrollableState { super.initState(); _indicatorAnimation = new ValuePerformance() ..duration = _kTabBarScroll - ..variable = new AnimatedRectValue(null, curve: ease); + ..variable = new AnimatedRectValue(null, curve: Curves.ease); scrollBehavior.isScrollable = config.isScrollable; } diff --git a/packages/flutter/lib/src/rendering/toggleable.dart b/packages/flutter/lib/src/rendering/toggleable.dart index f6e7879993d..658f65d71de 100644 --- a/packages/flutter/lib/src/rendering/toggleable.dart +++ b/packages/flutter/lib/src/rendering/toggleable.dart @@ -24,7 +24,7 @@ abstract class RenderToggleable extends RenderConstrainedBox { _onChanged = onChanged, super(additionalConstraints: new BoxConstraints.tight(size)) { _performance = new ValuePerformance( - variable: new AnimatedValue(0.0, end: 1.0, curve: easeIn, reverseCurve: easeOut), + variable: new AnimatedValue(0.0, end: 1.0, curve: Curves.easeIn, reverseCurve: Curves.easeOut), duration: _kToggleDuration, progress: _value ? 1.0 : 0.0 )..addListener(markNeedsPaint); diff --git a/packages/flutter/lib/src/widgets/animated_container.dart b/packages/flutter/lib/src/widgets/animated_container.dart index f205fdd2f9b..8a1831b4572 100644 --- a/packages/flutter/lib/src/widgets/animated_container.dart +++ b/packages/flutter/lib/src/widgets/animated_container.dart @@ -56,7 +56,7 @@ class AnimatedContainer extends StatefulComponent { this.transform, this.width, this.height, - this.curve: linear, + this.curve: Curves.linear, this.duration }) : super(key: key) { assert(margin == null || margin.isNonNegative); diff --git a/packages/flutter/lib/src/widgets/dismissable.dart b/packages/flutter/lib/src/widgets/dismissable.dart index f16c6531dda..a59c01fea30 100644 --- a/packages/flutter/lib/src/widgets/dismissable.dart +++ b/packages/flutter/lib/src/widgets/dismissable.dart @@ -13,7 +13,7 @@ import 'gesture_detector.dart'; const Duration _kCardDismissFadeout = const Duration(milliseconds: 200); const Duration _kCardDismissResize = const Duration(milliseconds: 300); -const Curve _kCardDismissResizeCurve = const Interval(0.4, 1.0, curve: ease); +const Curve _kCardDismissResizeCurve = const Interval(0.4, 1.0, curve: Curves.ease); const double _kMinFlingVelocity = 700.0; const double _kMinFlingVelocityDelta = 400.0; const double _kFlingVelocityScale = 1.0 / 300.0; diff --git a/packages/flutter/lib/src/widgets/navigator.dart b/packages/flutter/lib/src/widgets/navigator.dart index d708f4b6150..358cab089e8 100644 --- a/packages/flutter/lib/src/widgets/navigator.dart +++ b/packages/flutter/lib/src/widgets/navigator.dart @@ -307,10 +307,10 @@ class PageRoute extends PerformanceRoute { // TODO(jackson): Block input unless content is interactive return new SlideTransition( performance: performance, - position: new AnimatedValue(_kTransitionStartPoint, end: Point.origin, curve: easeOut), + position: new AnimatedValue(_kTransitionStartPoint, end: Point.origin, curve: Curves.easeOut), child: new FadeTransition( performance: performance, - opacity: new AnimatedValue(0.0, end: 1.0, curve: easeOut), + opacity: new AnimatedValue(0.0, end: 1.0, curve: Curves.easeOut), child: builder(new RouteArguments(navigator: navigator, previousPerformance: this.performance, nextPerformance: nextRoutePerformance)) ) ); diff --git a/packages/flutter/lib/src/widgets/scrollable.dart b/packages/flutter/lib/src/widgets/scrollable.dart index ea1cbf46686..a517dd5b3f3 100644 --- a/packages/flutter/lib/src/widgets/scrollable.dart +++ b/packages/flutter/lib/src/widgets/scrollable.dart @@ -181,7 +181,7 @@ abstract class ScrollableState extends State { dispatchOnScroll(); } - Future scrollTo(double newScrollOffset, { Duration duration, Curve curve: ease }) { + Future scrollTo(double newScrollOffset, { Duration duration, Curve curve: Curves.ease }) { if (newScrollOffset == _scrollOffset) return new Future.value(); @@ -692,7 +692,7 @@ class PageableList extends ScrollableList { this.onPageChanged, EdgeDims padding, this.duration: const Duration(milliseconds: 200), - this.curve: ease + this.curve: Curves.ease }) : super( key: key, initialScrollOffset: initialPage == null ? null : initialPage * itemExtent, diff --git a/packages/unit/test/widget/positioned_test.dart b/packages/unit/test/widget/positioned_test.dart index 7adecc8e58f..d6bcb0ebdec 100644 --- a/packages/unit/test/widget/positioned_test.dart +++ b/packages/unit/test/widget/positioned_test.dart @@ -19,7 +19,7 @@ void main() { new Rect.fromLTRB(80.0, 90.0, 90.0, 100.0), new Rect.fromLTRB(0.0, 10.0, 100.0, 110.0) ), - curve: linear + curve: Curves.linear ); final Performance performance = new Performance( duration: const Duration(seconds: 10)