@@ -99,19 +99,33 @@ export abstract class ToggleAnimationPlayer implements ToggleAnimationOwner, OnD
99
99
target = this . initializePlayer ( type , targetElement , callback ) ;
100
100
}
101
101
102
- if ( target . hasStarted ( ) ) {
102
+ // V.S. Jun 28th, 2021 #9783: player will NOT be initialized w/ null settings
103
+ // events will already be emitted
104
+ if ( ! target || target . hasStarted ( ) ) {
103
105
return ;
104
106
}
105
107
106
108
const targetEmitter = type === ANIMATION_TYPE . OPEN ? this . openAnimationStart : this . closeAnimationStart ;
107
109
targetEmitter . emit ( ) ;
108
- target . play ( ) ;
110
+ if ( target ) {
111
+ target . play ( ) ;
112
+ }
109
113
}
110
114
111
115
private initializePlayer ( type : ANIMATION_TYPE , targetElement : ElementRef , callback : ( ) => void ) : AnimationPlayer {
112
116
const oppositeType = type === ANIMATION_TYPE . OPEN ? ANIMATION_TYPE . CLOSE : ANIMATION_TYPE . OPEN ;
117
+ // V.S. Jun 28th, 2021 #9783: Treat falsy animation settings as disabled animations
118
+ const targetAnimationSettings = this . animationSettings || { closeAnimation : null , openAnimation : null } ;
113
119
const animationSettings = type === ANIMATION_TYPE . OPEN ?
114
- this . animationSettings . openAnimation : this . animationSettings . closeAnimation ;
120
+ targetAnimationSettings . openAnimation : targetAnimationSettings . closeAnimation ;
121
+ // V.S. Jun 28th, 2021 #9783: When no animation in target direction, emit start and done events and return
122
+ if ( ! animationSettings ) {
123
+ this . setCallback ( type , callback ) ;
124
+ const targetEmitter = type === ANIMATION_TYPE . OPEN ? this . openAnimationStart : this . closeAnimationStart ;
125
+ targetEmitter . emit ( ) ;
126
+ this . onDoneHandler ( type ) ;
127
+ return ;
128
+ }
115
129
const animation = useAnimation ( animationSettings ) ;
116
130
const animationBuilder = this . builder . build ( animation ) ;
117
131
const opposite = this . getPlayer ( oppositeType ) ;
@@ -132,23 +146,31 @@ export abstract class ToggleAnimationPlayer implements ToggleAnimationOwner, OnD
132
146
const target = this . getPlayer ( type ) ;
133
147
target . init ( ) ;
134
148
this . getPlayer ( type ) . setPosition ( 1 - oppositePosition ) ;
149
+ this . setCallback ( type , callback ) ;
150
+ target . onDone ( ( ) => {
151
+ this . onDoneHandler ( type ) ;
152
+ } ) ;
153
+ return target ;
154
+ }
155
+
156
+ private onDoneHandler ( type ) {
157
+ const targetEmitter = type === ANIMATION_TYPE . OPEN ? this . openAnimationDone : this . closeAnimationDone ;
158
+ const targetCallback = type === ANIMATION_TYPE . OPEN ? this . onOpenedCallback : this . onClosedCallback ;
159
+ targetCallback ( ) ;
160
+ if ( ! ( type === ANIMATION_TYPE . OPEN ? this . openInterrupted : this . closeInterrupted ) ) {
161
+ targetEmitter . emit ( ) ;
162
+ }
163
+ this . cleanUpPlayer ( type ) ;
164
+ }
165
+
166
+ private setCallback ( type : ANIMATION_TYPE , callback : ( ) => void ) {
135
167
if ( type === ANIMATION_TYPE . OPEN ) {
136
168
this . onOpenedCallback = callback ;
137
169
this . openInterrupted = false ;
138
170
} else if ( type === ANIMATION_TYPE . CLOSE ) {
139
171
this . onClosedCallback = callback ;
140
172
this . closeInterrupted = false ;
141
173
}
142
- const targetEmitter = type === ANIMATION_TYPE . OPEN ? this . openAnimationDone : this . closeAnimationDone ;
143
- target . onDone ( ( ) => {
144
- const targetCallback = type === ANIMATION_TYPE . OPEN ? this . onOpenedCallback : this . onClosedCallback ;
145
- targetCallback ( ) ;
146
- if ( ! ( type === ANIMATION_TYPE . OPEN ? this . openInterrupted : this . closeInterrupted ) ) {
147
- targetEmitter . emit ( ) ;
148
- }
149
- this . cleanUpPlayer ( type ) ;
150
- } ) ;
151
- return target ;
152
174
}
153
175
154
176
0 commit comments