Skip to content

Commit d37b9b8

Browse files
authored
fix(modal): improve card modal background transition from portrait to landscape (#30551)
Issue number: resolves internal --------- <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type (bugfix, feature, etc). Submit multiple pull requests if needed. --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying. --> Currently, if you have multiple card modals open in portrait view and then transition to landscape, the background will not be transformed properly and will not cover the entire screen as expected. https://github.com/user-attachments/assets/bb2c7015-adb6-4c3b-8bc5-13360275fcf4 ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> Now, we're correctly targeting the right element and will transform it as expected. This allows a more consistent UX for these transitions. https://github.com/user-attachments/assets/fff72387-d78b-4df4-a234-d89b54f694c4 ## Does this introduce a breaking change? - [ ] Yes - [X] No <!-- If this introduces a breaking change: 1. Describe the impact and migration path for existing applications below. 2. Update the BREAKING.md file with the breaking change. 3. Add "BREAKING CHANGE: [...]" to the commit description when merging. See https://github.com/ionic-team/ionic-framework/blob/main/docs/CONTRIBUTING.md#footer for more information. --> ## Other information <!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. --> [Relevant (broken) screen (main branch)](https://ionic-framework-git-main-ionic1.vercel.app/src/components/modal/test/card?ionic:mode=ios) [Relevant (fixed) screen (this branch)](https://ionic-framework-git-fix-modal-landscape-background-ionic1.vercel.app/src/components/modal/test/card?ionic:mode=ios)
1 parent 3f730ab commit d37b9b8

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

core/src/components/modal/animations/ios.transition.ts

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,22 @@ export const portraitToLandscapeTransition = (
7272
// need to care about layering and modal-specific styles.
7373
const toPresentingScale = SwipeToCloseDefaults.MIN_PRESENTING_SCALE;
7474
const fromTransform = `translateY(-10px) scale(${toPresentingScale})`;
75-
const toTransform = `translateY(-10px) scale(${toPresentingScale})`;
75+
const toTransform = `translateY(0px) scale(1)`;
7676

7777
presentingAnimation
78-
.addElement(presentingElRoot.querySelector('.modal-wrapper')!)
78+
.addElement(presentingEl)
7979
.afterStyles({
8080
transform: toTransform,
8181
})
8282
.fromTo('transform', fromTransform, toTransform)
83-
.fromTo('filter', 'contrast(0.85)', 'contrast(0.85)'); // Keep same contrast for card
83+
.fromTo('filter', 'contrast(0.85)', 'contrast(1)');
8484

8585
const shadowAnimation = createAnimation()
8686
.addElement(presentingElRoot.querySelector('.modal-shadow')!)
8787
.afterStyles({
8888
transform: toTransform,
89+
opacity: '0',
8990
})
90-
.fromTo('opacity', '0', '0') // Shadow stays hidden in landscape for card modals
9191
.fromTo('transform', fromTransform, toTransform);
9292

9393
baseAnimation.addAnimation([presentingAnimation, shadowAnimation]);
@@ -148,17 +148,8 @@ export const landscapeToPortraitTransition = (
148148

149149
presentingAnimation
150150
.addElement(presentingEl)
151-
.beforeStyles({
152-
transform: 'translateY(0px) scale(1)',
153-
'transform-origin': 'top center',
154-
overflow: 'hidden',
155-
})
156151
.afterStyles({
157152
transform: toTransform,
158-
'border-radius': '10px 10px 0 0',
159-
filter: 'contrast(0.85)',
160-
overflow: 'hidden',
161-
'transform-origin': 'top center',
162153
})
163154
.beforeAddWrite(() => bodyEl.style.setProperty('background-color', 'black'))
164155
.keyframes([
@@ -173,22 +164,21 @@ export const landscapeToPortraitTransition = (
173164
// to handle layering and modal-specific styles.
174165
const toPresentingScale = SwipeToCloseDefaults.MIN_PRESENTING_SCALE;
175166
const fromTransform = `translateY(-10px) scale(${toPresentingScale})`;
176-
const toTransform = `translateY(-10px) scale(${toPresentingScale})`;
167+
const toTransform = `translateY(0) scale(1)`;
177168

178169
presentingAnimation
179-
.addElement(presentingElRoot.querySelector('.modal-wrapper')!)
170+
.addElement(presentingEl)
180171
.afterStyles({
181172
transform: toTransform,
182173
})
183-
.fromTo('transform', fromTransform, toTransform)
184-
.fromTo('filter', 'contrast(0.85)', 'contrast(0.85)'); // Keep same contrast for card
174+
.fromTo('transform', fromTransform, toTransform);
185175

186176
const shadowAnimation = createAnimation()
187177
.addElement(presentingElRoot.querySelector('.modal-shadow')!)
188178
.afterStyles({
189179
transform: toTransform,
180+
opacity: '0',
190181
})
191-
.fromTo('opacity', '0', '0') // Shadow stays hidden
192182
.fromTo('transform', fromTransform, toTransform);
193183

194184
baseAnimation.addAnimation([presentingAnimation, shadowAnimation]);

core/src/components/modal/modal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ export class Modal implements ComponentInterface, OverlayInterface {
11221122
wrapperEl.style.opacity = '1';
11231123
}
11241124

1125-
if (presentingElement) {
1125+
if (presentingElement?.tagName === 'ION-MODAL') {
11261126
const isPortrait = window.innerWidth < 768;
11271127

11281128
if (isPortrait) {

0 commit comments

Comments
 (0)