1- import { reverseAnimationResolver } from '../../../core/utils' ;
1+ import { AnimationReferenceMetadata } from '@angular/animations' ;
2+ import { isHorizontalAnimation , isVerticalAnimation , reverseAnimationResolver } from '../../../core/utils' ;
23import { ConnectedFit , HorizontalAlignment , VerticalAlignment } from './../utilities' ;
34import { BaseFitPositionStrategy } from './base-fit-position-strategy' ;
45
@@ -11,12 +12,10 @@ export class AutoPositionStrategy extends BaseFitPositionStrategy {
1112 /** @inheritdoc */
1213 protected fitInViewport ( element : HTMLElement , connectedFit : ConnectedFit ) {
1314 const transformString : string [ ] = [ ] ;
14- let flipped = false ;
1515 if ( connectedFit . fitHorizontal . back < 0 || connectedFit . fitHorizontal . forward < 0 ) {
1616 if ( this . canFlipHorizontal ( connectedFit ) ) {
1717 this . flipHorizontal ( ) ;
18- this . flipAnimation ( ) ;
19- flipped = true ;
18+ this . flipAnimation ( FlipDirection . horizontal ) ;
2019 } else {
2120 const horizontalPush = this . horizontalPush ( connectedFit ) ;
2221 transformString . push ( `translateX(${ horizontalPush } px)` ) ;
@@ -26,9 +25,7 @@ export class AutoPositionStrategy extends BaseFitPositionStrategy {
2625 if ( connectedFit . fitVertical . back < 0 || connectedFit . fitVertical . forward < 0 ) {
2726 if ( this . canFlipVertical ( connectedFit ) ) {
2827 this . flipVertical ( ) ;
29- if ( ! flipped ) {
30- this . flipAnimation ( ) ;
31- }
28+ this . flipAnimation ( FlipDirection . vertical ) ;
3229 } else {
3330 const verticalPush = this . verticalPush ( connectedFit ) ;
3431 transformString . push ( `translateY(${ verticalPush } px)` ) ;
@@ -159,14 +156,43 @@ export class AutoPositionStrategy extends BaseFitPositionStrategy {
159156 }
160157
161158 /**
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
163161 */
164- private flipAnimation ( ) {
162+ private flipAnimation ( flipDirection : FlipDirection ) : void {
165163 if ( this . settings . openAnimation ) {
166- this . settings . openAnimation = reverseAnimationResolver ( this . settings . openAnimation ) ;
164+ this . settings . openAnimation = this . updateAnimation ( this . settings . openAnimation , flipDirection ) ;
167165 }
168166 if ( this . settings . closeAnimation ) {
169- this . settings . closeAnimation = reverseAnimationResolver ( this . settings . closeAnimation ) ;
167+ this . settings . closeAnimation = this . updateAnimation ( this . settings . closeAnimation , flipDirection ) ;
170168 }
171169 }
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
172198}
0 commit comments