Commit f79fdff2 authored by Adam Barth's avatar Adam Barth

Move animation curves into a Curves namespace

parent 529fa95f
...@@ -67,14 +67,14 @@ class TestBed extends NodeWithSize { ...@@ -67,14 +67,14 @@ class TestBed extends NodeWithSize {
// Animate obstacle // Animate obstacle
ActionSequence seq = new ActionSequence([ 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(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, 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)); _obstacle.actions.run(new ActionRepeatForever(seq));
seq = new ActionSequence([ seq = new ActionSequence([
new ActionTween((a) => _obstacle.scale = a, 1.0, 2.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, easeInOut) new ActionTween((a) => _obstacle.scale = a, 2.0, 1.0, 2.0, Curves.easeInOut)
]); ]);
_obstacle.actions.run(new ActionRepeatForever(seq)); _obstacle.actions.run(new ActionRepeatForever(seq));
......
...@@ -17,8 +17,8 @@ class ProgressIndicatorAppState extends State<ProgressIndicatorApp> { ...@@ -17,8 +17,8 @@ class ProgressIndicatorAppState extends State<ProgressIndicatorApp> {
..variable = new AnimatedValue<double>( ..variable = new AnimatedValue<double>(
0.0, 0.0,
end: 1.0, end: 1.0,
curve: new Interval(0.0, 0.9, curve: ease), curve: new Interval(0.0, 0.9, curve: Curves.ease),
reverseCurve: ease reverseCurve: Curves.ease
); );
valueAnimation.addStatusListener((PerformanceStatus status) { valueAnimation.addStatusListener((PerformanceStatus status) {
if (status == PerformanceStatus.dismissed || status == PerformanceStatus.completed) if (status == PerformanceStatus.dismissed || status == PerformanceStatus.completed)
......
...@@ -29,7 +29,7 @@ class Linear implements Curve { ...@@ -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 /// 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 { 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 /// The smallest value for which this interval is 0.0
final double start; final double start;
...@@ -153,38 +153,43 @@ class ElasticInOutCurve implements Curve { ...@@ -153,38 +153,43 @@ class ElasticInOutCurve implements Curve {
} }
} }
/// A linear animation curve /// A collection of common animation curves.
const Linear linear = const Linear(); class Curves {
Curves._();
/// A cubic animation curve that speeds up quickly and ends slowly /// A linear animation curve
const Cubic ease = const Cubic(0.25, 0.1, 0.25, 1.0); static const Linear linear = const Linear();
/// A cubic animation curve that starts slowly and ends quickly /// A cubic animation curve that speeds up quickly and ends slowly
const Cubic easeIn = const Cubic(0.42, 0.0, 1.0, 1.0); static const Cubic ease = const Cubic(0.25, 0.1, 0.25, 1.0);
/// A cubic animation curve that starts quickly and ends slowly /// A cubic animation curve that starts slowly and ends quickly
const Cubic easeOut = const Cubic(0.0, 0.0, 0.58, 1.0); 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 /// A cubic animation curve that starts quickly and ends slowly
const Cubic easeInOut = const Cubic(0.42, 0.0, 0.58, 1.0); static const Cubic easeOut = const Cubic(0.0, 0.0, 0.58, 1.0);
/// An oscillating curve that grows in magnitude /// A cubic animation curve that starts slowly, speeds up, and then and ends slowly
const BounceInCurve bounceIn = const BounceInCurve(); 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 /// An oscillating curve that grows in magnitude
const BounceOutCurve bounceOut = const BounceOutCurve(); static const BounceInCurve bounceIn = const BounceInCurve();
/// An oscillating curve that first grows and then shrink in magnitude /// An oscillating curve that first grows and then shrink in magnitude
const BounceInOutCurve bounceInOut = const BounceInOutCurve(); static const BounceOutCurve bounceOut = const BounceOutCurve();
/// An oscillating curve that grows in magnitude while overshootings its bounds /// An oscillating curve that first grows and then shrink in magnitude
const ElasticInCurve elasticIn = const ElasticInCurve(); static const BounceInOutCurve bounceInOut = const BounceInOutCurve();
/// An oscillating curve that shrinks in magnitude while overshootings its bounds /// An oscillating curve that grows in magnitude while overshootings its bounds
const ElasticOutCurve elasticOut = const ElasticOutCurve(); static const ElasticInCurve elasticIn = const ElasticInCurve();
/// An oscillating curve that grows and then shrinks in magnitude while overshootings its bounds /// An oscillating curve that shrinks in magnitude while overshootings its bounds
const ElasticInOutCurve elasticInOut = const ElasticInOutCurve(); 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. /// An oscillating curve that grows and then shrinks in magnitude while overshootings its bounds
const Curve fastOutSlowIn = const Cubic(0.4, 0.0, 0.2, 1.0); 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);
}
...@@ -66,7 +66,7 @@ class SimulationStepper { ...@@ -66,7 +66,7 @@ class SimulationStepper {
/// ///
/// Returns a future that resolves when the timeline stops animating, /// Returns a future that resolves when the timeline stops animating,
/// typically when the timeline arives at the target value. /// 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(duration > Duration.ZERO);
assert(!isAnimating); assert(!isAnimating);
return _start(new _TweenSimulation(value, target, duration, curve)); return _start(new _TweenSimulation(value, target, duration, curve));
......
...@@ -142,7 +142,7 @@ class _DialogRoute extends PerformanceRoute { ...@@ -142,7 +142,7 @@ class _DialogRoute extends PerformanceRoute {
Widget build(NavigatorState navigator, PerformanceView nextRoutePerformance) { Widget build(NavigatorState navigator, PerformanceView nextRoutePerformance) {
return new FadeTransition( return new FadeTransition(
performance: performance, performance: performance,
opacity: new AnimatedValue<double>(0.0, end: 1.0, curve: easeOut), opacity: new AnimatedValue<double>(0.0, end: 1.0, curve: Curves.easeOut),
child: builder(new RouteArguments(navigator: navigator, previousPerformance: this.performance, nextPerformance: nextRoutePerformance)) child: builder(new RouteArguments(navigator: navigator, previousPerformance: this.performance, nextPerformance: nextRoutePerformance))
); );
} }
......
...@@ -83,7 +83,7 @@ class _Drawer extends StatelessComponent { ...@@ -83,7 +83,7 @@ class _Drawer extends StatelessComponent {
performance: performance, performance: performance,
position: new AnimatedValue<Point>(_kClosedPosition, end: _kOpenPosition), position: new AnimatedValue<Point>(_kClosedPosition, end: _kOpenPosition),
child: new AnimatedContainer( child: new AnimatedContainer(
curve: ease, curve: Curves.ease,
duration: _kThemeChangeDuration, duration: _kThemeChangeDuration,
decoration: new BoxDecoration( decoration: new BoxDecoration(
backgroundColor: Theme.of(context).canvasColor, backgroundColor: Theme.of(context).canvasColor,
......
...@@ -28,7 +28,7 @@ class _InkSplash { ...@@ -28,7 +28,7 @@ class _InkSplash {
_InkSplash(this.position, this.well) { _InkSplash(this.position, this.well) {
_targetRadius = _getSplashTargetSize(well.size, position); _targetRadius = _getSplashTargetSize(well.size, position);
_radius = new AnimatedValue<double>( _radius = new AnimatedValue<double>(
_kSplashInitialSize, end: _targetRadius, curve: easeOut); _kSplashInitialSize, end: _targetRadius, curve: Curves.easeOut);
_performance = new ValuePerformance<double>( _performance = new ValuePerformance<double>(
variable: _radius, variable: _radius,
......
...@@ -67,7 +67,7 @@ class Material extends StatelessComponent { ...@@ -67,7 +67,7 @@ class Material extends StatelessComponent {
return new DefaultTextStyle( return new DefaultTextStyle(
style: Theme.of(context).text.body1, style: Theme.of(context).text.body1,
child: new AnimatedContainer( child: new AnimatedContainer(
curve: ease, curve: Curves.ease,
duration: kThemeChangeDuration, duration: kThemeChangeDuration,
decoration: new BoxDecoration( decoration: new BoxDecoration(
backgroundColor: _getBackgroundColor(context), backgroundColor: _getBackgroundColor(context),
......
...@@ -45,7 +45,7 @@ class _ProgressIndicatorState extends State<ProgressIndicator> { ...@@ -45,7 +45,7 @@ class _ProgressIndicatorState extends State<ProgressIndicator> {
void initState() { void initState() {
super.initState(); super.initState();
_performance = new ValuePerformance<double>( _performance = new ValuePerformance<double>(
variable: new AnimatedValue<double>(0.0, end: 1.0, curve: ease), variable: new AnimatedValue<double>(0.0, end: 1.0, curve: Curves.ease),
duration: const Duration(milliseconds: 1500) duration: const Duration(milliseconds: 1500)
); );
_performance.addStatusListener((PerformanceStatus status) { _performance.addStatusListener((PerformanceStatus status) {
......
...@@ -26,9 +26,9 @@ class RadialReaction { ...@@ -26,9 +26,9 @@ class RadialReaction {
this.radius, this.radius,
Point startPosition Point startPosition
}) { }) {
_outerOpacity = new AnimatedValue<double>(0.0, end: _kMaxOpacity, curve: easeOut); _outerOpacity = new AnimatedValue<double>(0.0, end: _kMaxOpacity, curve: Curves.easeOut);
_innerCenter = new AnimatedValue<Point>(startPosition, end: center, curve: easeOut); _innerCenter = new AnimatedValue<Point>(startPosition, end: center, curve: Curves.easeOut);
_innerRadius = new AnimatedValue<double>(0.0, end: radius, curve: easeOut); _innerRadius = new AnimatedValue<double>(0.0, end: radius, curve: Curves.easeOut);
_showPerformance = new Performance(duration: _kShowDuration) _showPerformance = new Performance(duration: _kShowDuration)
..addListener(() { ..addListener(() {
_showPerformance.updateVariable(_outerOpacity); _showPerformance.updateVariable(_outerOpacity);
...@@ -36,7 +36,7 @@ class RadialReaction { ...@@ -36,7 +36,7 @@ class RadialReaction {
_showPerformance.updateVariable(_innerRadius); _showPerformance.updateVariable(_innerRadius);
}); });
_fade = new ValuePerformance<double>( _fade = new ValuePerformance<double>(
variable: new AnimatedValue<double>(1.0, end: 0.0, curve: easeIn), variable: new AnimatedValue<double>(1.0, end: 0.0, curve: Curves.easeIn),
duration: _kHideDuration duration: _kHideDuration
); );
} }
......
...@@ -62,7 +62,7 @@ class ScrollbarPainter extends ScrollableListPainter { ...@@ -62,7 +62,7 @@ class ScrollbarPainter extends ScrollableListPainter {
Future scrollStarted() { Future scrollStarted() {
_fade ??= new ValuePerformance<double>() _fade ??= new ValuePerformance<double>()
..duration = _kScrollbarThumbFadeDuration ..duration = _kScrollbarThumbFadeDuration
..variable = new AnimatedValue<double>(0.0, end: 1.0, curve: ease) ..variable = new AnimatedValue<double>(0.0, end: 1.0, curve: Curves.ease)
..addListener(() { ..addListener(() {
_opacity = _fade.value; _opacity = _fade.value;
renderer?.markNeedsPaint(); renderer?.markNeedsPaint();
......
...@@ -67,8 +67,8 @@ class SnackBar extends StatelessComponent { ...@@ -67,8 +67,8 @@ class SnackBar extends StatelessComponent {
height: new AnimatedValue<double>( height: new AnimatedValue<double>(
0.0, 0.0,
end: kSnackBarHeight, end: kSnackBarHeight,
curve: easeIn, curve: Curves.easeIn,
reverseCurve: easeOut reverseCurve: Curves.easeOut
), ),
child: new ClipRect( child: new ClipRect(
child: new OverflowBox( child: new OverflowBox(
......
...@@ -404,7 +404,7 @@ class _TabBarState extends ScrollableState<TabBar> { ...@@ -404,7 +404,7 @@ class _TabBarState extends ScrollableState<TabBar> {
super.initState(); super.initState();
_indicatorAnimation = new ValuePerformance<Rect>() _indicatorAnimation = new ValuePerformance<Rect>()
..duration = _kTabBarScroll ..duration = _kTabBarScroll
..variable = new AnimatedRectValue(null, curve: ease); ..variable = new AnimatedRectValue(null, curve: Curves.ease);
scrollBehavior.isScrollable = config.isScrollable; scrollBehavior.isScrollable = config.isScrollable;
} }
......
...@@ -24,7 +24,7 @@ abstract class RenderToggleable extends RenderConstrainedBox { ...@@ -24,7 +24,7 @@ abstract class RenderToggleable extends RenderConstrainedBox {
_onChanged = onChanged, _onChanged = onChanged,
super(additionalConstraints: new BoxConstraints.tight(size)) { super(additionalConstraints: new BoxConstraints.tight(size)) {
_performance = new ValuePerformance<double>( _performance = new ValuePerformance<double>(
variable: new AnimatedValue<double>(0.0, end: 1.0, curve: easeIn, reverseCurve: easeOut), variable: new AnimatedValue<double>(0.0, end: 1.0, curve: Curves.easeIn, reverseCurve: Curves.easeOut),
duration: _kToggleDuration, duration: _kToggleDuration,
progress: _value ? 1.0 : 0.0 progress: _value ? 1.0 : 0.0
)..addListener(markNeedsPaint); )..addListener(markNeedsPaint);
......
...@@ -56,7 +56,7 @@ class AnimatedContainer extends StatefulComponent { ...@@ -56,7 +56,7 @@ class AnimatedContainer extends StatefulComponent {
this.transform, this.transform,
this.width, this.width,
this.height, this.height,
this.curve: linear, this.curve: Curves.linear,
this.duration this.duration
}) : super(key: key) { }) : super(key: key) {
assert(margin == null || margin.isNonNegative); assert(margin == null || margin.isNonNegative);
......
...@@ -13,7 +13,7 @@ import 'gesture_detector.dart'; ...@@ -13,7 +13,7 @@ import 'gesture_detector.dart';
const Duration _kCardDismissFadeout = const Duration(milliseconds: 200); const Duration _kCardDismissFadeout = const Duration(milliseconds: 200);
const Duration _kCardDismissResize = const Duration(milliseconds: 300); 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 _kMinFlingVelocity = 700.0;
const double _kMinFlingVelocityDelta = 400.0; const double _kMinFlingVelocityDelta = 400.0;
const double _kFlingVelocityScale = 1.0 / 300.0; const double _kFlingVelocityScale = 1.0 / 300.0;
......
...@@ -307,10 +307,10 @@ class PageRoute extends PerformanceRoute { ...@@ -307,10 +307,10 @@ class PageRoute extends PerformanceRoute {
// TODO(jackson): Block input unless content is interactive // TODO(jackson): Block input unless content is interactive
return new SlideTransition( return new SlideTransition(
performance: performance, performance: performance,
position: new AnimatedValue<Point>(_kTransitionStartPoint, end: Point.origin, curve: easeOut), position: new AnimatedValue<Point>(_kTransitionStartPoint, end: Point.origin, curve: Curves.easeOut),
child: new FadeTransition( child: new FadeTransition(
performance: performance, performance: performance,
opacity: new AnimatedValue<double>(0.0, end: 1.0, curve: easeOut), opacity: new AnimatedValue<double>(0.0, end: 1.0, curve: Curves.easeOut),
child: builder(new RouteArguments(navigator: navigator, previousPerformance: this.performance, nextPerformance: nextRoutePerformance)) child: builder(new RouteArguments(navigator: navigator, previousPerformance: this.performance, nextPerformance: nextRoutePerformance))
) )
); );
......
...@@ -181,7 +181,7 @@ abstract class ScrollableState<T extends Scrollable> extends State<T> { ...@@ -181,7 +181,7 @@ abstract class ScrollableState<T extends Scrollable> extends State<T> {
dispatchOnScroll(); dispatchOnScroll();
} }
Future scrollTo(double newScrollOffset, { Duration duration, Curve curve: ease }) { Future scrollTo(double newScrollOffset, { Duration duration, Curve curve: Curves.ease }) {
if (newScrollOffset == _scrollOffset) if (newScrollOffset == _scrollOffset)
return new Future.value(); return new Future.value();
...@@ -692,7 +692,7 @@ class PageableList<T> extends ScrollableList<T> { ...@@ -692,7 +692,7 @@ class PageableList<T> extends ScrollableList<T> {
this.onPageChanged, this.onPageChanged,
EdgeDims padding, EdgeDims padding,
this.duration: const Duration(milliseconds: 200), this.duration: const Duration(milliseconds: 200),
this.curve: ease this.curve: Curves.ease
}) : super( }) : super(
key: key, key: key,
initialScrollOffset: initialPage == null ? null : initialPage * itemExtent, initialScrollOffset: initialPage == null ? null : initialPage * itemExtent,
......
...@@ -19,7 +19,7 @@ void main() { ...@@ -19,7 +19,7 @@ void main() {
new Rect.fromLTRB(80.0, 90.0, 90.0, 100.0), new Rect.fromLTRB(80.0, 90.0, 90.0, 100.0),
new Rect.fromLTRB(0.0, 10.0, 100.0, 110.0) new Rect.fromLTRB(0.0, 10.0, 100.0, 110.0)
), ),
curve: linear curve: Curves.linear
); );
final Performance performance = new Performance( final Performance performance = new Performance(
duration: const Duration(seconds: 10) duration: const Duration(seconds: 10)
......
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