66 * found in the LICENSE file at https://angular.io/license
77 */
88
9- import { AnimationGroupPlayer } from '../animation/animation_group_player' ;
10- import { AnimationPlayer } from '../animation/animation_player' ;
11- import { queueAnimation } from '../animation/animation_queue' ;
12- import { AnimationTransitionEvent } from '../animation/animation_transition_event' ;
13- import { ViewAnimationMap } from '../animation/view_animation_map' ;
149import { ChangeDetectorRef , ChangeDetectorStatus } from '../change_detection/change_detection' ;
1510import { Injector } from '../di/injector' ;
1611import { ListWrapper } from '../facade/collection' ;
1712import { isPresent } from '../facade/lang' ;
1813import { WtfScopeFn , wtfCreateScope , wtfLeave } from '../profile/profile' ;
1914import { RenderComponentType , RenderDebugInfo , Renderer } from '../render/api' ;
2015
16+ import { AnimationViewContext } from './animation_view_context' ;
2117import { DebugContext , StaticNodeDebugInfo } from './debug_context' ;
2218import { AppElement } from './element' ;
2319import { ElementInjector } from './element_injector' ;
@@ -49,10 +45,7 @@ export abstract class AppView<T> {
4945 renderer : Renderer ;
5046
5147 private _hasExternalHostElement : boolean ;
52-
53- public animationPlayers = new ViewAnimationMap ( ) ;
54-
55- private _animationListeners = new Map < any , _AnimationOutputHandler [ ] > ( ) ;
48+ private _animationContext : AnimationViewContext ;
5649
5750 public context : T ;
5851
@@ -68,60 +61,14 @@ export abstract class AppView<T> {
6861 }
6962 }
7063
71- get destroyed ( ) : boolean { return this . cdMode === ChangeDetectorStatus . Destroyed ; }
72-
73- cancelActiveAnimation ( element : any , animationName : string , removeAllAnimations : boolean = false ) {
74- if ( removeAllAnimations ) {
75- this . animationPlayers . findAllPlayersByElement ( element ) . forEach ( player => player . destroy ( ) ) ;
76- } else {
77- var player = this . animationPlayers . find ( element , animationName ) ;
78- if ( isPresent ( player ) ) {
79- player . destroy ( ) ;
80- }
81- }
82- }
83-
84- queueAnimation (
85- element : any , animationName : string , player : AnimationPlayer , totalTime : number ,
86- fromState : string , toState : string ) : void {
87- queueAnimation ( player ) ;
88- var event = new AnimationTransitionEvent (
89- { 'fromState' : fromState , 'toState' : toState , 'totalTime' : totalTime } ) ;
90- this . animationPlayers . set ( element , animationName , player ) ;
91-
92- player . onDone ( ( ) => {
93- // TODO: make this into a datastructure for done|start
94- this . triggerAnimationOutput ( element , animationName , 'done' , event ) ;
95- this . animationPlayers . remove ( element , animationName ) ;
96- } ) ;
97-
98- player . onStart ( ( ) => { this . triggerAnimationOutput ( element , animationName , 'start' , event ) ; } ) ;
99- }
100-
101- triggerAnimationOutput (
102- element : any , animationName : string , phase : string , event : AnimationTransitionEvent ) {
103- var listeners = this . _animationListeners . get ( element ) ;
104- if ( isPresent ( listeners ) && listeners . length ) {
105- for ( let i = 0 ; i < listeners . length ; i ++ ) {
106- let listener = listeners [ i ] ;
107- // we check for both the name in addition to the phase in the event
108- // that there may be more than one @trigger on the same element
109- if ( listener . eventName === animationName && listener . eventPhase === phase ) {
110- listener . handler ( event ) ;
111- break ;
112- }
113- }
64+ get animationContext ( ) : AnimationViewContext {
65+ if ( ! this . _animationContext ) {
66+ this . _animationContext = new AnimationViewContext ( ) ;
11467 }
68+ return this . _animationContext ;
11569 }
11670
117- registerAnimationOutput (
118- element : any , eventName : string , eventPhase : string , eventHandler : Function ) : void {
119- var animations = this . _animationListeners . get ( element ) ;
120- if ( ! isPresent ( animations ) ) {
121- this . _animationListeners . set ( element , animations = [ ] ) ;
122- }
123- animations . push ( new _AnimationOutputHandler ( eventName , eventPhase , eventHandler ) ) ;
124- }
71+ get destroyed ( ) : boolean { return this . cdMode === ChangeDetectorStatus . Destroyed ; }
12572
12673 create ( context : T , givenProjectableNodes : Array < any | any [ ] > , rootSelectorOrNode : string | any ) :
12774 AppElement {
@@ -234,11 +181,11 @@ export abstract class AppView<T> {
234181 this . destroyInternal ( ) ;
235182 this . dirtyParentQueriesInternal ( ) ;
236183
237- if ( this . animationPlayers . length == 0 ) {
238- this . renderer . destroyView ( hostElement , this . allNodes ) ;
184+ if ( this . _animationContext ) {
185+ this . _animationContext . onAllActiveAnimationsDone (
186+ ( ) => this . renderer . destroyView ( hostElement , this . allNodes ) ) ;
239187 } else {
240- var player = new AnimationGroupPlayer ( this . animationPlayers . getAllPlayers ( ) ) ;
241- player . onDone ( ( ) => { this . renderer . destroyView ( hostElement , this . allNodes ) ; } ) ;
188+ this . renderer . destroyView ( hostElement , this . allNodes ) ;
242189 }
243190 }
244191
@@ -254,11 +201,11 @@ export abstract class AppView<T> {
254201
255202 detach ( ) : void {
256203 this . detachInternal ( ) ;
257- if ( this . animationPlayers . length == 0 ) {
258- this . renderer . detachView ( this . flatRootNodes ) ;
204+ if ( this . _animationContext ) {
205+ this . _animationContext . onAllActiveAnimationsDone (
206+ ( ) => this . renderer . detachView ( this . flatRootNodes ) ) ;
259207 } else {
260- var player = new AnimationGroupPlayer ( this . animationPlayers . getAllPlayers ( ) ) ;
261- player . onDone ( ( ) => { this . renderer . detachView ( this . flatRootNodes ) ; } ) ;
208+ this . renderer . detachView ( this . flatRootNodes ) ;
262209 }
263210 }
264211
@@ -466,7 +413,3 @@ function _findLastRenderNode(node: any): any {
466413 }
467414 return lastNode ;
468415}
469-
470- class _AnimationOutputHandler {
471- constructor ( public eventName : string , public eventPhase : string , public handler : Function ) { }
472- }
0 commit comments