-
Notifications
You must be signed in to change notification settings - Fork 13.4k
fix(modal): support iOS card view transitions for viewport changes #30520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3738016
fix(modal): support ios card view transitions for viewport changes
ShaneK 0deee3d
merge
ShaneK 112929c
fix(modal): clarity around mobile/portrait terminology
ShaneK 50f8f64
Merge branch 'main' of github.com:ionic-team/ionic-framework into FW-…
ShaneK da06a67
fix(modal): properly hadnling presenting element when starting in por…
ShaneK ef498b2
Merge branch 'main' of github.com:ionic-team/ionic-framework into FW-…
ShaneK 67f1d05
fix(modal): fixing dismiss animation in portrait view so it restores …
ShaneK 2cc4a5c
fix(modal): trigger view transition manually on cleanup to ensure we'…
ShaneK 159ec7d
fix(modal): resetting dismiss gesture when transitioning sizes
ShaneK a5501fb
fix(modal): cleaning up transition for cards when moving from landsca…
ShaneK 8acfb31
fix(modal): fixing card modal positioning when resetting animation af…
ShaneK 51fb559
fix(lint): running lint fix
ShaneK d3b968b
chore(modal): comments
ShaneK 278c2d7
refactor(modal): moving to @Listen instead of a manual resize listener
ShaneK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,198 @@ | ||
| import { createAnimation } from '@utils/animation/animation'; | ||
| import { getElementRoot } from '@utils/helpers'; | ||
|
|
||
| import type { Animation } from '../../../interface'; | ||
| import { SwipeToCloseDefaults } from '../gestures/swipe-to-close'; | ||
| import type { ModalAnimationOptions } from '../modal-interface'; | ||
|
|
||
| /** | ||
| * Transition animation from portrait view to landscape view | ||
| * This handles the case where a card modal is open in portrait view | ||
| * and the user switches to landscape view | ||
| */ | ||
| export const portraitToLandscapeTransition = ( | ||
| baseEl: HTMLElement, | ||
| opts: ModalAnimationOptions, | ||
| duration = 300 | ||
| ): Animation => { | ||
| const { presentingEl } = opts; | ||
|
|
||
| if (!presentingEl) { | ||
| // No transition needed for non-card modals | ||
| return createAnimation('portrait-to-landscape-transition'); | ||
| } | ||
|
|
||
| const presentingElIsCardModal = | ||
| presentingEl.tagName === 'ION-MODAL' && (presentingEl as HTMLIonModalElement).presentingElement !== undefined; | ||
| const presentingElRoot = getElementRoot(presentingEl); | ||
| const bodyEl = document.body; | ||
|
|
||
| const baseAnimation = createAnimation('portrait-to-landscape-transition') | ||
| .addElement(baseEl) | ||
| .easing('cubic-bezier(0.32,0.72,0,1)') | ||
| .duration(duration); | ||
|
|
||
| const presentingAnimation = createAnimation().beforeStyles({ | ||
| transform: 'translateY(0)', | ||
| 'transform-origin': 'top center', | ||
| overflow: 'hidden', | ||
| }); | ||
|
|
||
| if (!presentingElIsCardModal) { | ||
| // The presenting element is not a card modal, so we do not | ||
| // need to care about layering and modal-specific styles. | ||
| const root = getElementRoot(baseEl); | ||
| const wrapperAnimation = createAnimation() | ||
| .addElement(root.querySelectorAll('.modal-wrapper, .modal-shadow')!) | ||
| .fromTo('opacity', '1', '1'); // Keep wrapper visible in landscape | ||
|
|
||
| const backdropAnimation = createAnimation() | ||
| .addElement(root.querySelector('ion-backdrop')!) | ||
| .fromTo('opacity', 'var(--backdrop-opacity)', 'var(--backdrop-opacity)'); // Keep backdrop visible | ||
|
|
||
| // Animate presentingEl from portrait state back to normal | ||
| const transformOffset = !CSS.supports('width', 'max(0px, 1px)') ? '30px' : 'max(30px, var(--ion-safe-area-top))'; | ||
| const toPresentingScale = SwipeToCloseDefaults.MIN_PRESENTING_SCALE; | ||
| const fromTransform = `translateY(${transformOffset}) scale(${toPresentingScale})`; | ||
|
|
||
| presentingAnimation | ||
| .addElement(presentingEl) | ||
| .afterStyles({ | ||
| transform: 'translateY(0px) scale(1)', | ||
| 'border-radius': '0px', | ||
| }) | ||
| .beforeAddWrite(() => bodyEl.style.setProperty('background-color', '')) | ||
| .fromTo('transform', fromTransform, 'translateY(0px) scale(1)') | ||
| .fromTo('filter', 'contrast(0.85)', 'contrast(1)') | ||
| .fromTo('border-radius', '10px 10px 0 0', '0px'); | ||
|
|
||
| baseAnimation.addAnimation([presentingAnimation, wrapperAnimation, backdropAnimation]); | ||
| } else { | ||
| // The presenting element is a card modal, so we do | ||
| // need to care about layering and modal-specific styles. | ||
| const toPresentingScale = SwipeToCloseDefaults.MIN_PRESENTING_SCALE; | ||
| const fromTransform = `translateY(-10px) scale(${toPresentingScale})`; | ||
| const toTransform = `translateY(-10px) scale(${toPresentingScale})`; | ||
|
|
||
| presentingAnimation | ||
| .addElement(presentingElRoot.querySelector('.modal-wrapper')!) | ||
| .afterStyles({ | ||
| transform: toTransform, | ||
| }) | ||
| .fromTo('transform', fromTransform, toTransform) | ||
| .fromTo('filter', 'contrast(0.85)', 'contrast(0.85)'); // Keep same contrast for card | ||
|
|
||
| const shadowAnimation = createAnimation() | ||
| .addElement(presentingElRoot.querySelector('.modal-shadow')!) | ||
| .afterStyles({ | ||
| transform: toTransform, | ||
| }) | ||
| .fromTo('opacity', '0', '0') // Shadow stays hidden in landscape for card modals | ||
| .fromTo('transform', fromTransform, toTransform); | ||
|
|
||
| baseAnimation.addAnimation([presentingAnimation, shadowAnimation]); | ||
| } | ||
|
|
||
| return baseAnimation; | ||
| }; | ||
|
|
||
| /** | ||
| * Transition animation from landscape view to portrait view | ||
| * This handles the case where a card modal is open in landscape view | ||
| * and the user switches to portrait view | ||
| */ | ||
| export const landscapeToPortraitTransition = ( | ||
| baseEl: HTMLElement, | ||
| opts: ModalAnimationOptions, | ||
| duration = 300 | ||
| ): Animation => { | ||
| const { presentingEl } = opts; | ||
|
|
||
| if (!presentingEl) { | ||
| // No transition needed for non-card modals | ||
| return createAnimation('landscape-to-portrait-transition'); | ||
| } | ||
|
|
||
| const presentingElIsCardModal = | ||
| presentingEl.tagName === 'ION-MODAL' && (presentingEl as HTMLIonModalElement).presentingElement !== undefined; | ||
| const presentingElRoot = getElementRoot(presentingEl); | ||
| const bodyEl = document.body; | ||
|
|
||
| const baseAnimation = createAnimation('landscape-to-portrait-transition') | ||
| .addElement(baseEl) | ||
| .easing('cubic-bezier(0.32,0.72,0,1)') | ||
| .duration(duration); | ||
|
|
||
| const presentingAnimation = createAnimation().beforeStyles({ | ||
| transform: 'translateY(0)', | ||
| 'transform-origin': 'top center', | ||
| overflow: 'hidden', | ||
| }); | ||
|
|
||
| if (!presentingElIsCardModal) { | ||
| // The presenting element is not a card modal, so we do not | ||
| // need to care about layering and modal-specific styles. | ||
| const root = getElementRoot(baseEl); | ||
| const wrapperAnimation = createAnimation() | ||
| .addElement(root.querySelectorAll('.modal-wrapper, .modal-shadow')!) | ||
| .fromTo('opacity', '1', '1'); // Keep wrapper visible | ||
|
|
||
| const backdropAnimation = createAnimation() | ||
| .addElement(root.querySelector('ion-backdrop')!) | ||
| .fromTo('opacity', 'var(--backdrop-opacity)', 'var(--backdrop-opacity)'); // Keep backdrop visible | ||
|
|
||
| // Animate presentingEl from normal state to portrait state | ||
| const transformOffset = !CSS.supports('width', 'max(0px, 1px)') ? '30px' : 'max(30px, var(--ion-safe-area-top))'; | ||
| const toPresentingScale = SwipeToCloseDefaults.MIN_PRESENTING_SCALE; | ||
| const toTransform = `translateY(${transformOffset}) scale(${toPresentingScale})`; | ||
|
|
||
| presentingAnimation | ||
| .addElement(presentingEl) | ||
| .beforeStyles({ | ||
| transform: 'translateY(0px) scale(1)', | ||
| 'transform-origin': 'top center', | ||
| overflow: 'hidden', | ||
| }) | ||
| .afterStyles({ | ||
| transform: toTransform, | ||
| 'border-radius': '10px 10px 0 0', | ||
| filter: 'contrast(0.85)', | ||
| overflow: 'hidden', | ||
| 'transform-origin': 'top center', | ||
| }) | ||
| .beforeAddWrite(() => bodyEl.style.setProperty('background-color', 'black')) | ||
| .keyframes([ | ||
| { offset: 0, transform: 'translateY(0px) scale(1)', filter: 'contrast(1)', borderRadius: '0px' }, | ||
| { offset: 0.2, transform: 'translateY(0px) scale(1)', filter: 'contrast(1)', borderRadius: '10px 10px 0 0' }, | ||
| { offset: 1, transform: toTransform, filter: 'contrast(0.85)', borderRadius: '10px 10px 0 0' }, | ||
| ]); | ||
|
|
||
| baseAnimation.addAnimation([presentingAnimation, wrapperAnimation, backdropAnimation]); | ||
| } else { | ||
| // The presenting element is also a card modal, so we need | ||
| // to handle layering and modal-specific styles. | ||
| const toPresentingScale = SwipeToCloseDefaults.MIN_PRESENTING_SCALE; | ||
| const fromTransform = `translateY(-10px) scale(${toPresentingScale})`; | ||
| const toTransform = `translateY(-10px) scale(${toPresentingScale})`; | ||
|
|
||
| presentingAnimation | ||
| .addElement(presentingElRoot.querySelector('.modal-wrapper')!) | ||
| .afterStyles({ | ||
| transform: toTransform, | ||
| }) | ||
| .fromTo('transform', fromTransform, toTransform) | ||
| .fromTo('filter', 'contrast(0.85)', 'contrast(0.85)'); // Keep same contrast for card | ||
|
|
||
| const shadowAnimation = createAnimation() | ||
| .addElement(presentingElRoot.querySelector('.modal-shadow')!) | ||
| .afterStyles({ | ||
| transform: toTransform, | ||
| }) | ||
| .fromTo('opacity', '0', '0') // Shadow stays hidden | ||
| .fromTo('transform', fromTransform, toTransform); | ||
|
|
||
| baseAnimation.addAnimation([presentingAnimation, shadowAnimation]); | ||
| } | ||
|
|
||
| return baseAnimation; | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.