77 */
88
99import {
10- ANIMATION_QUEUE ,
1110 AnimationCallbackEvent ,
1211 AnimationFunction ,
1312 MAX_ANIMATION_TIMEOUT ,
1413} from '../../animation/interfaces' ;
1514import { getLView , getCurrentTNode } from '../state' ;
16- import { RENDERER , INJECTOR , CONTEXT , LView , ANIMATIONS } from '../interfaces/view' ;
15+ import { RENDERER , INJECTOR , CONTEXT , LView } from '../interfaces/view' ;
1716import { getNativeByTNode } from '../util/view_utils' ;
1817import { performanceMarkFeature } from '../../util/performance' ;
1918import { Renderer } from '../interfaces/renderer' ;
2019import { NgZone } from '../../zone' ;
2120import { determineLongestAnimation , allLeavingAnimations } from '../../animation/longest_animation' ;
2221import { TNode } from '../interfaces/node' ;
2322import { promiseWithResolvers } from '../../util/promise_with_resolvers' ;
24- import { Injector } from '../../di' ;
25- import { afterEveryRender } from '../after_render/hooks' ;
2623
2724import {
2825 addAnimationToLView ,
@@ -47,6 +44,7 @@ import {
4744 trackEnterClasses ,
4845 trackLeavingNodes ,
4946} from '../../animation/utils' ;
47+ import { initializeAnimationQueueScheduler , queueEnterAnimations } from '../../animation/queue' ;
5048
5149/**
5250 * Instruction to handle the `animate.enter` behavior for class bindings.
@@ -77,7 +75,10 @@ export function ɵɵanimateEnter(value: string | Function): typeof ɵɵanimateEn
7775 runEnterAnimation ( lView , tNode , value ) ,
7876 ) ;
7977
80- queueEnterAnimations ( lView ) ;
78+ initializeAnimationQueueScheduler ( lView [ INJECTOR ] ) ;
79+
80+ // it's unclear why we need to queue animations here, but without this, animating through host bindings fails
81+ queueEnterAnimations ( lView [ INJECTOR ] , getLViewEnterAnimations ( lView ) ) ;
8182
8283 return ɵɵanimateEnter ; // For chaining
8384}
@@ -198,7 +199,10 @@ export function ɵɵanimateEnterListener(value: AnimationFunction): typeof ɵɵa
198199 runEnterAnimationFunction ( lView , tNode , value ) ,
199200 ) ;
200201
201- queueEnterAnimations ( lView ) ;
202+ initializeAnimationQueueScheduler ( lView [ INJECTOR ] ) ;
203+
204+ // it's unclear why we need to queue animations here, but without this, animating through host bindings fails
205+ queueEnterAnimations ( lView [ INJECTOR ] , getLViewEnterAnimations ( lView ) ) ;
202206
203207 return ɵɵanimateEnterListener ;
204208}
@@ -244,7 +248,7 @@ export function ɵɵanimateLeave(value: string | Function): typeof ɵɵanimateLe
244248 runLeaveAnimations ( lView , tNode , value ) ,
245249 ) ;
246250
247- enableAnimationQueueScheduler ( lView [ INJECTOR ] ) ;
251+ initializeAnimationQueueScheduler ( lView [ INJECTOR ] ) ;
248252
249253 return ɵɵanimateLeave ; // For chaining
250254}
@@ -377,7 +381,7 @@ export function ɵɵanimateLeaveListener(value: AnimationFunction): typeof ɵɵa
377381 runLeaveAnimationFunction ( lView , tNode , value ) ,
378382 ) ;
379383
380- enableAnimationQueueScheduler ( lView [ INJECTOR ] ) ;
384+ initializeAnimationQueueScheduler ( lView [ INJECTOR ] ) ;
381385
382386 return ɵɵanimateLeaveListener ; // For chaining
383387}
@@ -465,38 +469,3 @@ function runLeaveAnimationFunction(
465469 // Ensure cleanup if the LView is destroyed before the animation runs.
466470 return { promise, resolve} ;
467471}
468-
469- function queueEnterAnimations ( lView : LView ) {
470- enableAnimationQueueScheduler ( lView [ INJECTOR ] ) ;
471- const enterAnimations = lView [ ANIMATIONS ] ?. enter ;
472- if ( enterAnimations ) {
473- const animationQueue = lView [ INJECTOR ] . get ( ANIMATION_QUEUE ) ;
474- for ( const [ _ , nodeAnimations ] of enterAnimations ) {
475- for ( const animateFn of nodeAnimations . animateFns ) {
476- animationQueue . queue . add ( animateFn ) ;
477- }
478- }
479- }
480- }
481-
482- function enableAnimationQueueScheduler ( injector : Injector ) {
483- const animationQueue = injector . get ( ANIMATION_QUEUE ) ;
484- // We only need to schedule the animation queue runner once per application.
485- if ( ! animationQueue . isScheduled ) {
486- afterEveryRender (
487- ( ) => {
488- runQueuedAnimations ( injector ) ;
489- } ,
490- { injector} ,
491- ) ;
492- animationQueue . isScheduled = true ;
493- }
494- }
495-
496- function runQueuedAnimations ( injector : Injector ) {
497- const animationQueue = injector . get ( ANIMATION_QUEUE ) ;
498- for ( let animateFn of animationQueue . queue ) {
499- animateFn ( ) ;
500- }
501- animationQueue . queue . clear ( ) ;
502- }
0 commit comments