Skip to content

Commit 3ce54fe

Browse files
committed
refactor(overlay): flip animation depending on direction, #8238
1 parent 78ffe1c commit 3ce54fe

File tree

2 files changed

+156
-11
lines changed

2 files changed

+156
-11
lines changed

Diff for: projects/igniteui-angular/src/lib/core/utils.ts

+119
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,14 @@ export function reverseAnimationResolver(animation: AnimationReferenceMetadata):
428428
return oppositeAnimation.get(animation) ?? animation;
429429
}
430430

431+
export function isHorizontalAnimation(animation: AnimationReferenceMetadata): boolean {
432+
return horizontalAnimations.includes(animation);
433+
}
434+
435+
export function isVerticalAnimation(animation: AnimationReferenceMetadata): boolean {
436+
return verticalAnimations.includes(animation);
437+
}
438+
431439
const oppositeAnimation: Map<AnimationReferenceMetadata, AnimationReferenceMetadata> = new Map([
432440
[fadeIn, fadeIn],
433441
[fadeOut, fadeOut],
@@ -545,3 +553,114 @@ const oppositeAnimation: Map<AnimationReferenceMetadata, AnimationReferenceMetad
545553
[swingInLeftBck, swingInRightBck],
546554
[swingOutLeftBck, swingOutRightBck],
547555
]);
556+
557+
const horizontalAnimations: AnimationReferenceMetadata[] = [
558+
flipRight,
559+
flipLeft,
560+
flipVerFwd,
561+
flipVerBck,
562+
rotateInRight,
563+
rotateOutRight,
564+
rotateInLeft,
565+
rotateOutLeft,
566+
rotateInTr,
567+
rotateOutTr,
568+
rotateInBr,
569+
rotateOutBr,
570+
rotateInBl,
571+
rotateOutBl,
572+
rotateInTl,
573+
rotateOutTl,
574+
scaleInRight,
575+
scaleOutRight,
576+
scaleInLeft,
577+
scaleOutLeft,
578+
scaleInTr,
579+
scaleOutTr,
580+
scaleInBr,
581+
scaleOutBr,
582+
scaleInBl,
583+
scaleOutBl,
584+
scaleInTl,
585+
scaleOutTl,
586+
scaleInHorLeft,
587+
scaleOutHorLeft,
588+
scaleInHorRight,
589+
scaleOutHorRight,
590+
slideInRight,
591+
slideOutRight,
592+
slideInLeft,
593+
slideOutLeft,
594+
slideInTr,
595+
slideOutTr,
596+
slideInBr,
597+
slideOutBr,
598+
slideInBl,
599+
slideOutBl,
600+
slideInTl,
601+
slideOutTl,
602+
swingInRightFwd,
603+
swingOutRightFwd,
604+
swingInLeftFwd,
605+
swingOutLefttFwd,
606+
swingInRightBck,
607+
swingOutRightBck,
608+
swingInLeftBck,
609+
swingOutLeftBck,
610+
];
611+
const verticalAnimations: AnimationReferenceMetadata[] = [
612+
flipTop,
613+
flipBottom,
614+
flipHorFwd,
615+
flipHorBck,
616+
growVerIn,
617+
growVerOut,
618+
rotateInTop,
619+
rotateOutTop,
620+
rotateInBottom,
621+
rotateOutBottom,
622+
rotateInTr,
623+
rotateOutTr,
624+
rotateInBr,
625+
rotateOutBr,
626+
rotateInBl,
627+
rotateOutBl,
628+
rotateInTl,
629+
rotateOutTl,
630+
scaleInTop,
631+
scaleOutTop,
632+
scaleInBottom,
633+
scaleOutBottom,
634+
scaleInTr,
635+
scaleOutTr,
636+
scaleInBr,
637+
scaleOutBr,
638+
scaleInBl,
639+
scaleOutBl,
640+
scaleInTl,
641+
scaleOutTl,
642+
scaleInVerTop,
643+
scaleOutVerTop,
644+
scaleInVerBottom,
645+
scaleOutVerBottom,
646+
slideInTop,
647+
slideOutTop,
648+
slideInBottom,
649+
slideOutBottom,
650+
slideInTr,
651+
slideOutTr,
652+
slideInBr,
653+
slideOutBr,
654+
slideInBl,
655+
slideOutBl,
656+
slideInTl,
657+
slideOutTl,
658+
swingInTopFwd,
659+
swingOutTopFwd,
660+
swingInBottomFwd,
661+
swingOutBottomFwd,
662+
swingInTopBck,
663+
swingOutTopBck,
664+
swingInBottomBck,
665+
swingOutBottomBck,
666+
];

Diff for: 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)