@@ -155,6 +155,11 @@ public TickerFuture forward(float? from = null) {
155
155
156
156
return true ;
157
157
} ) ;
158
+ D . assert (
159
+ this . _ticker != null ,
160
+ "AnimationController.forward() called after AnimationController.dispose()\n " +
161
+ "AnimationController methods should not be used after calling dispose."
162
+ ) ;
158
163
this . _direction = _AnimationDirection . forward ;
159
164
if ( from != null ) {
160
165
this . setValue ( from . Value ) ;
@@ -175,6 +180,11 @@ public TickerFuture reverse(float? from = null) {
175
180
176
181
return true ;
177
182
} ) ;
183
+ D . assert (
184
+ this . _ticker != null ,
185
+ "AnimationController.reverse() called after AnimationController.dispose()\n " +
186
+ "AnimationController methods should not be used after calling dispose."
187
+ ) ;
178
188
this . _direction = _AnimationDirection . reverse ;
179
189
if ( from != null ) {
180
190
this . setValue ( from . Value ) ;
@@ -184,11 +194,27 @@ public TickerFuture reverse(float? from = null) {
184
194
}
185
195
186
196
public TickerFuture animateTo ( float target , TimeSpan ? duration = null , Curve curve = null ) {
197
+ D . assert (
198
+ this . _ticker != null ,
199
+ "AnimationController.animateTo() called after AnimationController.dispose()\n " +
200
+ "AnimationController methods should not be used after calling dispose."
201
+ ) ;
187
202
curve = curve ?? Curves . linear ;
188
203
189
204
this . _direction = _AnimationDirection . forward ;
190
205
return this . _animateToInternal ( target , duration : duration , curve : curve ) ;
191
206
}
207
+
208
+ TickerFuture animateBack ( float target , TimeSpan ? duration , Curve curve = null ) {
209
+ D . assert (
210
+ this . _ticker != null ,
211
+ "AnimationController.animateBack() called after AnimationController.dispose()\n " +
212
+ "AnimationController methods should not be used after calling dispose."
213
+ ) ;
214
+ curve = curve ?? Curves . linear ;
215
+ this . _direction = _AnimationDirection . reverse ;
216
+ return this . _animateToInternal ( target , duration , curve ) ;
217
+ }
192
218
193
219
TickerFuture _animateToInternal ( float target , TimeSpan ? duration = null , Curve curve = null ) {
194
220
curve = curve ?? Curves . linear ;
@@ -236,7 +262,7 @@ TickerFuture _animateToInternal(float target, TimeSpan? duration = null, Curve c
236
262
new _InterpolationSimulation ( this . _value , target , simulationDuration . Value , curve ) ) ;
237
263
}
238
264
239
- public TickerFuture repeat ( float ? min = null , float ? max = null , TimeSpan ? period = null ) {
265
+ public TickerFuture repeat ( float ? min = null , float ? max = null , bool reverse = false , TimeSpan ? period = null ) {
240
266
min = min ?? this . lowerBound ;
241
267
max = max ?? this . upperBound ;
242
268
period = period ?? this . duration ;
@@ -252,7 +278,11 @@ public TickerFuture repeat(float? min = null, float? max = null, TimeSpan? perio
252
278
253
279
return true ;
254
280
} ) ;
255
- return this . animateWith ( new _RepeatingSimulation ( min . Value , max . Value , period . Value ) ) ;
281
+
282
+ D . assert ( max >= min ) ;
283
+ D . assert ( max <= this . upperBound && min >= this . lowerBound ) ;
284
+ D . assert ( reverse != null ) ;
285
+ return this . animateWith ( new _RepeatingSimulation ( this . _value , min . Value , max . Value , reverse , period . Value ) ) ;
256
286
}
257
287
258
288
public TickerFuture fling ( float velocity = 1.0f ) {
@@ -395,21 +425,32 @@ public override bool isDone(float timeInSeconds) {
395
425
}
396
426
397
427
class _RepeatingSimulation : Simulation {
398
- internal _RepeatingSimulation ( float min , float max , TimeSpan period ) {
428
+ internal _RepeatingSimulation ( float initialValue , float min , float max , bool reverse , TimeSpan period ) {
399
429
this . _min = min ;
400
430
this . _max = max ;
401
431
this . _periodInSeconds = ( float ) period . Ticks / TimeSpan . TicksPerSecond ;
432
+ this . _initialT = ( max == min ) ? 0.0f : ( initialValue / ( max - min ) ) * ( period . Ticks / TimeSpan . TicksPerSecond ) ;
402
433
D . assert ( this . _periodInSeconds > 0.0f ) ;
434
+ D . assert ( this . _initialT >= 0.0f ) ;
403
435
}
404
436
405
437
readonly float _min ;
406
438
readonly float _max ;
407
439
readonly float _periodInSeconds ;
440
+ readonly bool _reverse ;
441
+ readonly float _initialT ;
408
442
409
443
public override float x ( float timeInSeconds ) {
410
444
D . assert ( timeInSeconds >= 0.0f ) ;
411
- float t = ( timeInSeconds / this . _periodInSeconds ) % 1.0f ;
412
- return MathUtils . lerpFloat ( this . _min , this . _max , t ) ;
445
+ float totalTimeInSeconds = timeInSeconds + this . _initialT ;
446
+ float t = ( totalTimeInSeconds / this . _periodInSeconds ) % 1.0f ;
447
+ bool _isPlayingReverse = ( ( int ) ( totalTimeInSeconds / this . _periodInSeconds ) ) % 2 == 1 ;
448
+
449
+ if ( this . _reverse && _isPlayingReverse ) {
450
+ return MathUtils . lerpFloat ( this . _max , this . _min , t ) ;
451
+ } else {
452
+ return MathUtils . lerpFloat ( this . _min , this . _max , t ) ;
453
+ }
413
454
}
414
455
415
456
public override float dx ( float timeInSeconds ) {
0 commit comments