1
- import { reverseAnimationResolver } from '../../../core/utils' ;
1
+ import { AnimationReferenceMetadata } from '@angular/animations' ;
2
+ import { isHorizontalAnimation , isVerticalAnimation , reverseAnimationResolver } from '../../../core/utils' ;
2
3
import { ConnectedFit , HorizontalAlignment , VerticalAlignment } from './../utilities' ;
3
4
import { BaseFitPositionStrategy } from './base-fit-position-strategy' ;
4
5
@@ -11,12 +12,10 @@ export class AutoPositionStrategy extends BaseFitPositionStrategy {
11
12
/** @inheritdoc */
12
13
protected fitInViewport ( element : HTMLElement , connectedFit : ConnectedFit ) {
13
14
const transformString : string [ ] = [ ] ;
14
- let flipped = false ;
15
15
if ( connectedFit . fitHorizontal . back < 0 || connectedFit . fitHorizontal . forward < 0 ) {
16
16
if ( this . canFlipHorizontal ( connectedFit ) ) {
17
17
this . flipHorizontal ( ) ;
18
- this . flipAnimation ( ) ;
19
- flipped = true ;
18
+ this . flipAnimation ( FlipDirection . horizontal ) ;
20
19
} else {
21
20
const horizontalPush = this . horizontalPush ( connectedFit ) ;
22
21
transformString . push ( `translateX(${ horizontalPush } px)` ) ;
@@ -26,9 +25,7 @@ export class AutoPositionStrategy extends BaseFitPositionStrategy {
26
25
if ( connectedFit . fitVertical . back < 0 || connectedFit . fitVertical . forward < 0 ) {
27
26
if ( this . canFlipVertical ( connectedFit ) ) {
28
27
this . flipVertical ( ) ;
29
- if ( ! flipped ) {
30
- this . flipAnimation ( ) ;
31
- }
28
+ this . flipAnimation ( FlipDirection . vertical ) ) ;
32
29
} else {
33
30
const verticalPush = this . verticalPush ( connectedFit ) ;
34
31
transformString . push ( `translateY(${ verticalPush } px)` ) ;
@@ -159,14 +156,43 @@ export class AutoPositionStrategy extends BaseFitPositionStrategy {
159
156
}
160
157
161
158
/**
162
- * Changes open and close animation with opposite animation if one exists
159
+ * Changes open and close animation with reverse animation if one exists
160
+ * @param flipDirection direction for which to change the animations
163
161
*/
164
- private flipAnimation ( ) {
162
+ private flipAnimation ( flipDirection : FlipDirection ) : void {
165
163
if ( this . settings . openAnimation ) {
166
- this . settings . openAnimation = reverseAnimationResolver ( this . settings . openAnimation ) ;
164
+ this . settings . openAnimation = this . updateAnimation ( this . settings . openAnimation , flipDirection ) ;
167
165
}
168
166
if ( this . settings . closeAnimation ) {
169
- this . settings . closeAnimation = reverseAnimationResolver ( this . settings . closeAnimation ) ;
167
+ this . settings . closeAnimation = this . updateAnimation ( this . settings . closeAnimation , flipDirection ) ;
170
168
}
171
169
}
170
+
171
+ /**
172
+ * Tries to find the reverse animation according to provided direction
173
+ * @param animation animation to update
174
+ * @param direction required animation direction
175
+ * @returns reverse animation in given direction if one exists
176
+ */
177
+ private updateAnimation ( animation : AnimationReferenceMetadata , direction : FlipDirection ) : AnimationReferenceMetadata {
178
+ switch ( direction ) {
179
+ case FlipDirection . horizontal :
180
+ if ( isHorizontalAnimation ( animation ) ) {
181
+ return reverseAnimationResolver ( animation ) ;
182
+ }
183
+ break ;
184
+ case FlipDirection . vertical :
185
+ if ( isVerticalAnimation ( animation ) ) {
186
+ return reverseAnimationResolver ( animation ) ;
187
+ }
188
+ break ;
189
+ }
190
+
191
+ return animation ;
192
+ }
193
+ }
194
+
195
+ enum FlipDirection {
196
+ horizontal ,
197
+ vertical
172
198
}
0 commit comments