diff --git a/packages/flutter/lib/src/animation/curves.dart b/packages/flutter/lib/src/animation/curves.dart index 6383e0292c..17e3d3db05 100644 --- a/packages/flutter/lib/src/animation/curves.dart +++ b/packages/flutter/lib/src/animation/curves.dart @@ -28,6 +28,16 @@ class Linear implements Curve { double transform(double t) => t; } +/// A sawtooth curve that repeats a given number of times over the unit interval. +class SawTooth implements Curve { + const SawTooth(this.count); + final int count; + double transform(double t) { + t *= count; + return t - t.truncateToDouble(); + } +} + /// 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: Curves.linear }); diff --git a/packages/flutter/lib/src/material/progress_indicator.dart b/packages/flutter/lib/src/material/progress_indicator.dart index dbc241107f..866c1ac2cf 100644 --- a/packages/flutter/lib/src/material/progress_indicator.dart +++ b/packages/flutter/lib/src/material/progress_indicator.dart @@ -191,42 +191,22 @@ class CircularProgressIndicator extends ProgressIndicator { _CircularProgressIndicatorState createState() => new _CircularProgressIndicatorState(); } -// This class assumes that the incoming animation is a linear 0.0..1.0. -class _RepeatingCurveTween extends Animatable { - _RepeatingCurveTween({ this.curve, this.repeats }); - - Curve curve; - int repeats; - - double evaluate(Animation animation) { - double t = animation.value; - t *= repeats; - t -= t.truncateToDouble(); - if (t == 0.0 || t == 1.0) { - assert(curve.transform(t).round() == t); - return t; - } - return curve.transform(t); - } -} - // Tweens used by circular progress indicator -final _RepeatingCurveTween _kStrokeHeadTween = new _RepeatingCurveTween( - curve: new Interval(0.0, 0.5, curve: Curves.fastOutSlowIn), - repeats: 5 -); +final Animatable _kStrokeHeadTween = new CurveTween( + curve: new Interval(0.0, 0.5, curve: Curves.fastOutSlowIn) +).chain(new CurveTween( + curve: new SawTooth(5) +)); -final _RepeatingCurveTween _kStrokeTailTween = new _RepeatingCurveTween( - curve: new Interval(0.5, 1.0, curve: Curves.fastOutSlowIn), - repeats: 5 -); +final Animatable _kStrokeTailTween = new CurveTween( + curve: new Interval(0.5, 1.0, curve: Curves.fastOutSlowIn) +).chain(new CurveTween( + curve: new SawTooth(5) +)); -final StepTween _kStepTween = new StepTween(begin: 0, end: 5); +final Animatable _kStepTween = new StepTween(begin: 0, end: 5); -final _RepeatingCurveTween _kRotationTween = new _RepeatingCurveTween( - curve: Curves.linear, - repeats: 5 -); +final Animatable _kRotationTween = new CurveTween(curve: new SawTooth(5)); class _CircularProgressIndicatorState extends State { AnimationController _animationController;