Skip to content

Commit 96631dd

Browse files
committed
refactor(overlay): flip animation depending on direction, #8238
1 parent 5f88a83 commit 96631dd

File tree

2 files changed

+156
-11
lines changed

2 files changed

+156
-11
lines changed

projects/igniteui-angular/src/lib/core/utils.ts

+119
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,14 @@ export function reverseAnimationResolver(animation: AnimationReferenceMetadata):
476476
return oppositeAnimation.get(animation) ?? animation;
477477
}
478478

479+
export function isHorizontalAnimation(animation: AnimationReferenceMetadata): boolean {
480+
return horizontalAnimations.includes(animation);
481+
}
482+
483+
export function isVerticalAnimation(animation: AnimationReferenceMetadata): boolean {
484+
return verticalAnimations.includes(animation);
485+
}
486+
479487
const oppositeAnimation: Map<AnimationReferenceMetadata, AnimationReferenceMetadata> = new Map([
480488
[fadeIn, fadeIn],
481489
[fadeOut, fadeOut],
@@ -593,3 +601,114 @@ const oppositeAnimation: Map<AnimationReferenceMetadata, AnimationReferenceMetad
593601
[swingInLeftBck, swingInRightBck],
594602
[swingOutLeftBck, swingOutRightBck],
595603
]);
604+
605+
const horizontalAnimations: AnimationReferenceMetadata[] = [
606+
flipRight,
607+
flipLeft,
608+
flipVerFwd,
609+
flipVerBck,
610+
rotateInRight,
611+
rotateOutRight,
612+
rotateInLeft,
613+
rotateOutLeft,
614+
rotateInTr,
615+
rotateOutTr,
616+
rotateInBr,
617+
rotateOutBr,
618+
rotateInBl,
619+
rotateOutBl,
620+
rotateInTl,
621+
rotateOutTl,
622+
scaleInRight,
623+
scaleOutRight,
624+
scaleInLeft,
625+
scaleOutLeft,
626+
scaleInTr,
627+
scaleOutTr,
628+
scaleInBr,
629+
scaleOutBr,
630+
scaleInBl,
631+
scaleOutBl,
632+
scaleInTl,
633+
scaleOutTl,
634+
scaleInHorLeft,
635+
scaleOutHorLeft,
636+
scaleInHorRight,
637+
scaleOutHorRight,
638+
slideInRight,
639+
slideOutRight,
640+
slideInLeft,
641+
slideOutLeft,
642+
slideInTr,
643+
slideOutTr,
644+
slideInBr,
645+
slideOutBr,
646+
slideInBl,
647+
slideOutBl,
648+
slideInTl,
649+
slideOutTl,
650+
swingInRightFwd,
651+
swingOutRightFwd,
652+
swingInLeftFwd,
653+
swingOutLefttFwd,
654+
swingInRightBck,
655+
swingOutRightBck,
656+
swingInLeftBck,
657+
swingOutLeftBck,
658+
];
659+
const verticalAnimations: AnimationReferenceMetadata[] = [
660+
flipTop,
661+
flipBottom,
662+
flipHorFwd,
663+
flipHorBck,
664+
growVerIn,
665+
growVerOut,
666+
rotateInTop,
667+
rotateOutTop,
668+
rotateInBottom,
669+
rotateOutBottom,
670+
rotateInTr,
671+
rotateOutTr,
672+
rotateInBr,
673+
rotateOutBr,
674+
rotateInBl,
675+
rotateOutBl,
676+
rotateInTl,
677+
rotateOutTl,
678+
scaleInTop,
679+
scaleOutTop,
680+
scaleInBottom,
681+
scaleOutBottom,
682+
scaleInTr,
683+
scaleOutTr,
684+
scaleInBr,
685+
scaleOutBr,
686+
scaleInBl,
687+
scaleOutBl,
688+
scaleInTl,
689+
scaleOutTl,
690+
scaleInVerTop,
691+
scaleOutVerTop,
692+
scaleInVerBottom,
693+
scaleOutVerBottom,
694+
slideInTop,
695+
slideOutTop,
696+
slideInBottom,
697+
slideOutBottom,
698+
slideInTr,
699+
slideOutTr,
700+
slideInBr,
701+
slideOutBr,
702+
slideInBl,
703+
slideOutBl,
704+
slideInTl,
705+
slideOutTl,
706+
swingInTopFwd,
707+
swingOutTopFwd,
708+
swingInBottomFwd,
709+
swingOutBottomFwd,
710+
swingInTopBck,
711+
swingOutTopBck,
712+
swingInBottomBck,
713+
swingOutBottomBck,
714+
];

projects/igniteui-angular/src/lib/services/overlay/position/auto-position-strategy.ts

+37-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { reverseAnimationResolver } from '../../../core/utils';
1+
import { AnimationReferenceMetadata } from '@angular/animations';
2+
import { isHorizontalAnimation, isVerticalAnimation, reverseAnimationResolver } from '../../../core/utils';
23
import { ConnectedFit, HorizontalAlignment, VerticalAlignment } from './../utilities';
34
import { 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

Comments
 (0)