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,7 @@ export class Animation {
297
297
* Play the animation.
298
298
*/
299
299
play ( opts ?: PlayOptions ) {
300
- const dur = this . getDuration ( opts ) ;
300
+ assert ( this . _raf , '_raf has to be valid' ) ;
301
301
302
302
// this is the top level animation and is in full control
303
303
// of when the async play() should actually kick off
@@ -311,22 +311,16 @@ export class Animation {
311
311
this . _clearAsync ( ) ;
312
312
313
313
// recursively kicks off the correct progress step for each child animation
314
+ // ******** DOM WRITE ****************
314
315
this . _playInit ( opts ) ;
315
316
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
317
// doubling up RAFs since this animation was probably triggered
325
318
// from an input event, and just having one RAF would have this code
326
319
// run within the same frame as the triggering input event, and the
327
320
// 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 ) ) ;
321
+ this . _raf ( ( ) => {
322
+ assert ( this . _raf , '_raf has to be valid' ) ;
323
+ this . _raf ( this . _playDomInspect . bind ( this , opts ) ) ;
330
324
} ) ;
331
325
}
332
326
@@ -367,26 +361,29 @@ export class Animation {
367
361
* NO RECURSION
368
362
* ROOT ANIMATION
369
363
*/
370
- _playDomInspect ( opts : PlayOptions ) {
364
+ _playDomInspect ( opts : PlayOptions , ) {
371
365
// fire off all the "before" function that have DOM READS in them
372
366
// elements will be in the DOM, however visibily hidden
373
367
// so we can read their dimensions if need be
374
368
// ******** 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
369
// ******** DOM WRITE ****************
381
- this . _beforeWriteFn ( ) ;
370
+ this . _beforeAnimation ( ) ;
371
+
372
+ // for the root animation only
373
+ // set the async TRANSITION END event
374
+ // and run onFinishes when the transition ends
375
+ const dur = this . getDuration ( opts ) ;
376
+ if ( this . _isAsync ) {
377
+ this . _asyncEnd ( dur , true ) ;
378
+ }
382
379
383
380
// ******** DOM WRITE ****************
384
381
this . _playProgress ( opts ) ;
385
382
386
- if ( this . _isAsync ) {
383
+ if ( this . _isAsync && this . _raf ) {
387
384
// this animation has a duration so we need another RAF
388
385
// for the CSS TRANSITION properties to kick in
389
- this . _raf && this . _raf ( this . _playToStep . bind ( this , 1 ) ) ;
386
+ this . _raf ( this . _playToStep . bind ( this , 1 ) ) ;
390
387
}
391
388
}
392
389
@@ -401,10 +398,6 @@ export class Animation {
401
398
this . _c [ i ] . _playProgress ( opts ) ;
402
399
}
403
400
404
- // stage all of the before css classes and inline styles
405
- // ******** DOM WRITE ****************
406
- this . _before ( ) ;
407
-
408
401
if ( this . _hasDur ) {
409
402
// set the CSS TRANSITION duration/easing
410
403
// ******** DOM WRITE ****************
@@ -418,15 +411,15 @@ export class Animation {
418
411
419
412
// since there was no animation, immediately run the after
420
413
// ******** DOM WRITE ****************
421
- this . _after ( ) ;
414
+ this . _afterAnimation ( ) ;
422
415
423
416
// this animation has no duration, so it has finished
424
417
// other animations could still be running
425
418
this . _didFinish ( true ) ;
426
419
}
427
420
}
428
421
429
- /**
422
+ /**
430
423
* @private
431
424
* DOM WRITE
432
425
* RECURSION
@@ -517,7 +510,7 @@ export class Animation {
517
510
518
511
// set the after styles
519
512
// ******** DOM WRITE ****************
520
- this . _after ( ) ;
513
+ this . _afterAnimation ( ) ;
521
514
522
515
// remove the will-change properties
523
516
// ******** DOM WRITE ****************
@@ -684,38 +677,72 @@ export class Animation {
684
677
685
678
/**
686
679
* @private
680
+ * DOM READ
687
681
* DOM WRITE
688
- * NO RECURSION
682
+ * RECURSION
683
+ */
684
+ _beforeAnimation ( ) {
685
+ // assert(this._beforeCalled === false, '_before has been called twice');
686
+ // this._beforeCalled = true;
687
+
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
689
709
*/
690
- _before ( ) {
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