Skip to content

Commit 8acfb31

Browse files
committed
fix(modal): fixing card modal positioning when resetting animation after view change
1 parent a5501fb commit 8acfb31

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

core/src/components/modal/modal.tsx

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { ComponentInterface, EventEmitter } from '@stencil/core';
22
import { Component, Element, Event, Host, Method, Prop, State, Watch, h, writeTask } from '@stencil/core';
33
import { findIonContent, printIonContentErrorMsg } from '@utils/content';
44
import { CoreDelegate, attachComponent, detachComponent } from '@utils/framework-delegate';
5-
import { raf, inheritAttributes, hasLazyBuild } from '@utils/helpers';
5+
import { raf, inheritAttributes, hasLazyBuild, getElementRoot } from '@utils/helpers';
66
import type { Attributes } from '@utils/helpers';
77
import { createLockController } from '@utils/lock-controller';
88
import { printIonWarning } from '@utils/logging';
@@ -1079,12 +1079,43 @@ export class Modal implements ComponentInterface, OverlayInterface {
10791079
}
10801080

10811081
if (this.animation) {
1082+
// Properly end the progress-based animation at initial state before destroying
1083+
// to avoid leaving modal in intermediate swipe position
1084+
this.animation.progressEnd(0, 0, 0);
10821085
this.animation.destroy();
10831086
this.animation = undefined;
10841087
}
10851088

1086-
// Reinitialize the swipe-to-close gesture with current state
1087-
this.initSwipeToClose();
1089+
// Minimal fix: timing + essential positioning
1090+
raf(() => {
1091+
this.ensureCorrectModalPosition();
1092+
this.initSwipeToClose();
1093+
});
1094+
}
1095+
1096+
private ensureCorrectModalPosition() {
1097+
const { el, presentingElement } = this;
1098+
const root = getElementRoot(el);
1099+
1100+
// Minimal fix: wrapper element and presenting element positioning only
1101+
const wrapperEl = root.querySelector('.modal-wrapper') as HTMLElement | null;
1102+
1103+
if (wrapperEl) {
1104+
wrapperEl.style.transform = 'translateY(0vh)';
1105+
wrapperEl.style.opacity = '1';
1106+
}
1107+
1108+
if (presentingElement) {
1109+
const isPortrait = window.innerWidth < 768;
1110+
1111+
if (isPortrait) {
1112+
const transformOffset = !CSS.supports('width', 'max(0px, 1px)') ? '30px' : 'max(30px, var(--ion-safe-area-top))';
1113+
const scale = 0.915; // SwipeToCloseDefaults.MIN_PRESENTING_SCALE
1114+
presentingElement.style.transform = `translateY(${transformOffset}) scale(${scale})`;
1115+
} else {
1116+
presentingElement.style.transform = 'translateY(0px) scale(1)';
1117+
}
1118+
}
10881119
}
10891120

10901121
render() {

0 commit comments

Comments
 (0)