1
1
import { CSS , nativeRaf , transitionEnd , nativeTimeout } from '../util/dom' ;
2
- import { isDefined } from '../util/util' ;
2
+ import { isDefined , assert } from '../util/util' ;
3
3
4
4
5
5
/**
@@ -297,7 +297,10 @@ export class Animation {
297
297
* Play the animation.
298
298
*/
299
299
play ( opts ?: PlayOptions ) {
300
- const dur = this . getDuration ( opts ) ;
300
+ // If the animation was already invalidated (it did finish), do nothing
301
+ if ( ! this . _raf ) {
302
+ return ;
303
+ }
301
304
302
305
// this is the top level animation and is in full control
303
306
// of when the async play() should actually kick off
@@ -311,22 +314,16 @@ export class Animation {
311
314
this . _clearAsync ( ) ;
312
315
313
316
// recursively kicks off the correct progress step for each child animation
317
+ // ******** DOM WRITE ****************
314
318
this . _playInit ( opts ) ;
315
319
316
- if ( this . _isAsync ) {
317
- // for the root animation only
318
- // set the async TRANSITION END event
319
- // and run onFinishes when the transition ends
320
- // ******** DOM WRITE ****************
321
- this . _asyncEnd ( dur , true ) ;
322
- }
323
-
324
320
// doubling up RAFs since this animation was probably triggered
325
321
// from an input event, and just having one RAF would have this code
326
322
// run within the same frame as the triggering input event, and the
327
323
// input event probably already did way too much work for one frame
328
- this . _raf && this . _raf ( ( ) => {
329
- this . _raf && this . _raf ( this . _playDomInspect . bind ( this , opts ) ) ;
324
+ this . _raf ( ( ) => {
325
+ assert ( this . _raf , '_raf has to be valid' ) ;
326
+ this . _raf ( this . _playDomInspect . bind ( this , opts ) ) ;
330
327
} ) ;
331
328
}
332
329
@@ -372,21 +369,24 @@ export class Animation {
372
369
// elements will be in the DOM, however visibily hidden
373
370
// so we can read their dimensions if need be
374
371
// ******** DOM READ ****************
375
- this . _beforeReadFn ( ) ;
376
-
377
- // ******** DOM READS ABOVE / DOM WRITES BELOW ****************
378
-
379
- // fire off all the "before" function that have DOM WRITES in them
380
372
// ******** DOM WRITE ****************
381
- this . _beforeWriteFn ( ) ;
373
+ this . _beforeAnimation ( ) ;
374
+
375
+ // for the root animation only
376
+ // set the async TRANSITION END event
377
+ // and run onFinishes when the transition ends
378
+ const dur = this . getDuration ( opts ) ;
379
+ if ( this . _isAsync ) {
380
+ this . _asyncEnd ( dur , true ) ;
381
+ }
382
382
383
383
// ******** DOM WRITE ****************
384
384
this . _playProgress ( opts ) ;
385
385
386
- if ( this . _isAsync ) {
386
+ if ( this . _isAsync && this . _raf ) {
387
387
// this animation has a duration so we need another RAF
388
388
// for the CSS TRANSITION properties to kick in
389
- this . _raf && this . _raf ( this . _playToStep . bind ( this , 1 ) ) ;
389
+ this . _raf ( this . _playToStep . bind ( this , 1 ) ) ;
390
390
}
391
391
}
392
392
@@ -401,10 +401,6 @@ export class Animation {
401
401
this . _c [ i ] . _playProgress ( opts ) ;
402
402
}
403
403
404
- // stage all of the before css classes and inline styles
405
- // ******** DOM WRITE ****************
406
- this . _before ( ) ;
407
-
408
404
if ( this . _hasDur ) {
409
405
// set the CSS TRANSITION duration/easing
410
406
// ******** DOM WRITE ****************
@@ -418,7 +414,7 @@ export class Animation {
418
414
419
415
// since there was no animation, immediately run the after
420
416
// ******** DOM WRITE ****************
421
- this . _after ( ) ;
417
+ this . _afterAnimation ( ) ;
422
418
423
419
// this animation has no duration, so it has finished
424
420
// other animations could still be running
@@ -517,7 +513,7 @@ export class Animation {
517
513
518
514
// set the after styles
519
515
// ******** DOM WRITE ****************
520
- this . _after ( ) ;
516
+ this . _afterAnimation ( ) ;
521
517
522
518
// remove the will-change properties
523
519
// ******** DOM WRITE ****************
@@ -684,38 +680,69 @@ export class Animation {
684
680
685
681
/**
686
682
* @private
683
+ * DOM READ
687
684
* DOM WRITE
688
- * NO RECURSION
685
+ * RECURSION
689
686
*/
690
- _before ( ) {
687
+ _beforeAnimation ( ) {
688
+ // fire off all the "before" function that have DOM READS in them
689
+ // elements will be in the DOM, however visibily hidden
690
+ // so we can read their dimensions if need be
691
+ // ******** DOM READ ****************
692
+ this . _fireBeforeReadFunc ( ) ;
693
+
694
+ // ******** DOM READS ABOVE / DOM WRITES BELOW ****************
695
+
696
+ // fire off all the "before" function that have DOM WRITES in them
697
+ // ******** DOM WRITE ****************
698
+ this . _fireBeforeWriteFunc ( ) ;
699
+
700
+ // stage all of the before css classes and inline styles
701
+ // ******** DOM WRITE ****************
702
+ this . _setBeforeStyles ( ) ;
703
+ }
704
+
705
+ /**
706
+ * @private
707
+ * DOM WRITE
708
+ * RECURSION
709
+ */
710
+ _setBeforeStyles ( ) {
711
+ for ( var i = 0 ; i < this . _cL ; i ++ ) {
712
+ this . _c [ i ] . _setBeforeStyles ( ) ;
713
+ }
714
+
691
715
// before the animations have started
692
- if ( ! this . _rv ) {
693
- let ele : HTMLElement ;
694
- for ( var i = 0 ; i < this . _eL ; i ++ ) {
695
- ele = this . _e [ i ] ;
716
+ // only set before styles if animation is not reversed
717
+ if ( this . _rv ) {
718
+ return ;
719
+ }
696
720
697
- // css classes to add before the animation
698
- if ( this . _bfAdd ) {
699
- for ( var j = 0 ; j < this . _bfAdd . length ; j ++ ) {
700
- // ******** DOM WRITE ****************
701
- ele . classList . add ( this . _bfAdd [ j ] ) ;
702
- }
721
+ let ele : HTMLElement ;
722
+ for ( var i = 0 ; i < this . _eL ; i ++ ) {
723
+ ele = this . _e [ i ] ;
724
+
725
+ // css classes to add before the animation
726
+ if ( this . _bfAdd ) {
727
+ for ( var j = 0 ; j < this . _bfAdd . length ; j ++ ) {
728
+ // ******** DOM WRITE ****************
729
+ ele . classList . add ( this . _bfAdd [ j ] ) ;
703
730
}
731
+ }
704
732
705
- // css classes to remove before the animation
706
- if ( this . _bfRm ) {
707
- for ( var j = 0 ; j < this . _bfRm . length ; j ++ ) {
708
- // ******** DOM WRITE ****************
709
- ele . classList . remove ( this . _bfRm [ j ] ) ;
710
- }
733
+ // css classes to remove before the animation
734
+ if ( this . _bfRm ) {
735
+ for ( var j = 0 ; j < this . _bfRm . length ; j ++ ) {
736
+ // ******** DOM WRITE ****************
737
+ ele . classList . remove ( this . _bfRm [ j ] ) ;
711
738
}
739
+ }
712
740
713
- // inline styles to add before the animation
714
- if ( this . _bfSty ) {
715
- for ( var prop in this . _bfSty ) {
716
- // ******** DOM WRITE ****************
717
- ( < any > ele ) . style [ prop ] = this . _bfSty [ prop ] ;
718
- }
741
+ // inline styles to add before the animation
742
+ if ( this . _bfSty ) {
743
+ for ( var prop in this . _bfSty ) {
744
+ // ******** DOM WRITE ****************
745
+ ( < any > ele ) . style [ prop ] = this . _bfSty [ prop ] ;
719
746
}
720
747
}
721
748
}
@@ -726,10 +753,10 @@ export class Animation {
726
753
* DOM READ
727
754
* RECURSION
728
755
*/
729
- _beforeReadFn ( ) {
756
+ _fireBeforeReadFunc ( ) {
730
757
for ( var i = 0 ; i < this . _cL ; i ++ ) {
731
758
// ******** DOM READ ****************
732
- this . _c [ i ] . _beforeReadFn ( ) ;
759
+ this . _c [ i ] . _fireBeforeReadFunc ( ) ;
733
760
}
734
761
735
762
if ( this . _rdFn ) {
@@ -745,10 +772,10 @@ export class Animation {
745
772
* DOM WRITE
746
773
* RECURSION
747
774
*/
748
- _beforeWriteFn ( ) {
775
+ _fireBeforeWriteFunc ( ) {
749
776
for ( var i = 0 ; i < this . _cL ; i ++ ) {
750
777
// ******** DOM WRITE ****************
751
- this . _c [ i ] . _beforeWriteFn ( ) ;
778
+ this . _c [ i ] . _fireBeforeWriteFunc ( ) ;
752
779
}
753
780
754
781
if ( this . _wrFn ) {
@@ -762,9 +789,13 @@ export class Animation {
762
789
/**
763
790
* @private
764
791
* DOM WRITE
765
- * NO RECURSION
792
+ * RECURSION
766
793
*/
767
- _after ( ) {
794
+ _afterAnimation ( ) {
795
+ for ( var i = 0 ; i < this . _cL ; i ++ ) {
796
+ this . _c [ i ] . _afterAnimation ( ) ;
797
+ }
798
+
768
799
let ele : HTMLElement ;
769
800
for ( var i = 0 ; i < this . _eL ; i ++ ) {
770
801
ele = this . _e [ i ] ;
@@ -828,7 +859,6 @@ export class Animation {
828
859
}
829
860
}
830
861
}
831
-
832
862
}
833
863
834
864
/**
@@ -864,15 +894,8 @@ export class Animation {
864
894
// ensure all past transition end events have been cleared
865
895
this . _clearAsync ( ) ;
866
896
867
- // fire off all the "before" function that have DOM READS in them
868
- // elements will be in the DOM, however visibily hidden
869
- // so we can read their dimensions if need be
870
- // ******** DOM READ ****************
871
- this . _beforeReadFn ( ) ;
872
-
873
- // fire off all the "before" function that have DOM WRITES in them
874
- // ******** DOM WRITE ****************
875
- this . _beforeWriteFn ( ) ;
897
+ // ******** DOM READ/WRITE ****************
898
+ this . _beforeAnimation ( ) ;
876
899
877
900
// ******** DOM WRITE ****************
878
901
this . _progressStart ( ) ;
@@ -889,9 +912,6 @@ export class Animation {
889
912
this . _c [ i ] . _progressStart ( ) ;
890
913
}
891
914
892
- // ******** DOM WRITE ****************
893
- this . _before ( ) ;
894
-
895
915
// force no duration, linear easing
896
916
// ******** DOM WRITE ****************
897
917
this . _setTrans ( 0 , true ) ;
@@ -971,7 +991,7 @@ export class Animation {
971
991
// ******** DOM WRITE ****************
972
992
this . _progress ( stepValue ) ;
973
993
this . _willChg ( false ) ;
974
- this . _after ( ) ;
994
+ this . _afterAnimation ( ) ;
975
995
this . _didFinish ( shouldComplete ) ;
976
996
977
997
} else {
0 commit comments