File tree Expand file tree Collapse file tree 2 files changed +37
-3
lines changed
Expand file tree Collapse file tree 2 files changed +37
-3
lines changed Original file line number Diff line number Diff line change @@ -417,11 +417,14 @@ const stagger = function(
417417 ) ;
418418} ;
419419
420- type LoopAnimationConfig = { iterations : number } ;
420+ type LoopAnimationConfig = {
421+ iterations : number ,
422+ resetBeforeIteration ?: boolean ,
423+ } ;
421424
422425const loop = function (
423426 animation : CompositeAnimation ,
424- { iterations = - 1 } : LoopAnimationConfig = { } ,
427+ { iterations = - 1 , resetBeforeIteration = true } : LoopAnimationConfig = { } ,
425428) : CompositeAnimation {
426429 let isFinished = false ;
427430 let iterationsSoFar = 0 ;
@@ -436,7 +439,7 @@ const loop = function(
436439 callback && callback ( result ) ;
437440 } else {
438441 iterationsSoFar ++ ;
439- animation . reset ( ) ;
442+ resetBeforeIteration && animation . reset ( ) ;
440443 animation . start ( restart ) ;
441444 }
442445 } ;
Original file line number Diff line number Diff line change @@ -445,6 +445,37 @@ describe('Animated tests', () => {
445445 } ) ;
446446 } ) ;
447447
448+ it ( 'does not reset animation in a loop if resetBeforeIteration is false' , ( ) => {
449+ const animation = {
450+ start : jest . fn ( ) ,
451+ reset : jest . fn ( ) ,
452+ _isUsingNativeDriver : ( ) => false ,
453+ } ;
454+ const cb = jest . fn ( ) ;
455+
456+ const loop = Animated . loop ( animation , { resetBeforeIteration : false } ) ;
457+
458+ expect ( animation . start ) . not . toBeCalled ( ) ;
459+
460+ loop . start ( cb ) ;
461+
462+ expect ( animation . start ) . toBeCalled ( ) ;
463+ expect ( animation . reset ) . not . toBeCalled ( ) ;
464+ expect ( cb ) . not . toBeCalled ( ) ;
465+
466+ animation . start . mock . calls [ 0 ] [ 0 ] ( { finished : true } ) ; // End of loop 1
467+ expect ( animation . reset ) . not . toBeCalled ( ) ;
468+ expect ( cb ) . not . toBeCalled ( ) ;
469+
470+ animation . start . mock . calls [ 0 ] [ 0 ] ( { finished : true } ) ; // End of loop 2
471+ expect ( animation . reset ) . not . toBeCalled ( ) ;
472+ expect ( cb ) . not . toBeCalled ( ) ;
473+
474+ animation . start . mock . calls [ 0 ] [ 0 ] ( { finished : true } ) ; // End of loop 3
475+ expect ( animation . reset ) . not . toBeCalled ( ) ;
476+ expect ( cb ) . not . toBeCalled ( ) ;
477+ } ) ;
478+
448479 describe ( 'Animated Parallel' , ( ) => {
449480 it ( 'works with an empty parallel' , ( ) => {
450481 const cb = jest . fn ( ) ;
You can’t perform that action at this time.
0 commit comments