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 {
// 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));
......
......@@ -17,8 +17,8 @@ class ProgressIndicatorAppState extends State<ProgressIndicatorApp> {
..variable = new AnimatedValue<double>(
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)
......
......@@ -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);
}
......@@ -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));
......
......@@ -142,7 +142,7 @@ class _DialogRoute extends PerformanceRoute {
Widget build(NavigatorState navigator, PerformanceView nextRoutePerformance) {
return new FadeTransition(
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))
);
}
......
......@@ -83,7 +83,7 @@ class _Drawer extends StatelessComponent {
performance: performance,
position: new AnimatedValue<Point>(_kClosedPosition, end: _kOpenPosition),
child: new AnimatedContainer(
curve: ease,
curve: Curves.ease,
duration: _kThemeChangeDuration,
decoration: new BoxDecoration(
backgroundColor: Theme.of(context).canvasColor,
......
......@@ -28,7 +28,7 @@ class _InkSplash {
_InkSplash(this.position, this.well) {
_targetRadius = _getSplashTargetSize(well.size, position);
_radius = new AnimatedValue<double>(
_kSplashInitialSize, end: _targetRadius, curve: easeOut);
_kSplashInitialSize, end: _targetRadius, curve: Curves.easeOut);
_performance = new ValuePerformance<double>(
variable: _radius,
......
......@@ -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),
......
......@@ -45,7 +45,7 @@ class _ProgressIndicatorState extends State<ProgressIndicator> {
void initState() {
super.initState();
_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)
);
_performance.addStatusListener((PerformanceStatus status) {
......
......@@ -26,9 +26,9 @@ class RadialReaction {
this.radius,
Point startPosition
}) {
_outerOpacity = new AnimatedValue<double>(0.0, end: _kMaxOpacity, curve: easeOut);
_innerCenter = new AnimatedValue<Point>(startPosition, end: center, curve: easeOut);
_innerRadius = new AnimatedValue<double>(0.0, end: radius, curve: easeOut);
_outerOpacity = new AnimatedValue<double>(0.0, end: _kMaxOpacity, curve: Curves.easeOut);
_innerCenter = new AnimatedValue<Point>(startPosition, end: center, curve: Curves.easeOut);
_innerRadius = new AnimatedValue<double>(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<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
);
}
......
......@@ -62,7 +62,7 @@ class ScrollbarPainter extends ScrollableListPainter {
Future scrollStarted() {
_fade ??= new ValuePerformance<double>()
..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(() {
_opacity = _fade.value;
renderer?.markNeedsPaint();
......
......@@ -67,8 +67,8 @@ class SnackBar extends StatelessComponent {
height: new AnimatedValue<double>(
0.0,
end: kSnackBarHeight,
curve: easeIn,
reverseCurve: easeOut
curve: Curves.easeIn,
reverseCurve: Curves.easeOut
),
child: new ClipRect(
child: new OverflowBox(
......
......@@ -404,7 +404,7 @@ class _TabBarState extends ScrollableState<TabBar> {
super.initState();
_indicatorAnimation = new ValuePerformance<Rect>()
..duration = _kTabBarScroll
..variable = new AnimatedRectValue(null, curve: ease);
..variable = new AnimatedRectValue(null, curve: Curves.ease);
scrollBehavior.isScrollable = config.isScrollable;
}
......
......@@ -24,7 +24,7 @@ abstract class RenderToggleable extends RenderConstrainedBox {
_onChanged = onChanged,
super(additionalConstraints: new BoxConstraints.tight(size)) {
_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,
progress: _value ? 1.0 : 0.0
)..addListener(markNeedsPaint);
......
......@@ -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);
......
......@@ -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;
......
......@@ -307,10 +307,10 @@ class PageRoute extends PerformanceRoute {
// TODO(jackson): Block input unless content is interactive
return new SlideTransition(
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(
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))
)
);
......
......@@ -181,7 +181,7 @@ abstract class ScrollableState<T extends Scrollable> extends State<T> {
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<T> extends ScrollableList<T> {
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,
......
......@@ -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)
......
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