|
1 | 1 | import type { ComponentInterface, EventEmitter } from '@stencil/core'; |
2 | | -import { Component, Element, Event, Host, Method, Prop, State, Watch, h, writeTask } from '@stencil/core'; |
| 2 | +import { Component, Element, Event, Host, Listen, Method, Prop, State, Watch, h, writeTask } from '@stencil/core'; |
3 | 3 | import { findIonContent, printIonContentErrorMsg } from '@utils/content'; |
4 | 4 | import { CoreDelegate, attachComponent, detachComponent } from '@utils/framework-delegate'; |
5 | 5 | import { raf, inheritAttributes, hasLazyBuild, getElementRoot } from '@utils/helpers'; |
@@ -92,7 +92,6 @@ export class Modal implements ComponentInterface, OverlayInterface { |
92 | 92 | private gestureAnimationDismissing = false; |
93 | 93 |
|
94 | 94 | // View transition properties for handling portrait/landscape switches |
95 | | - private resizeListener?: () => void; |
96 | 95 | private currentViewIsPortrait?: boolean; |
97 | 96 | private viewTransitionAnimation?: Animation; |
98 | 97 | private resizeTimeout?: any; |
@@ -268,6 +267,19 @@ export class Modal implements ComponentInterface, OverlayInterface { |
268 | 267 | } |
269 | 268 | } |
270 | 269 |
|
| 270 | + @Listen('resize', { target: 'window' }) |
| 271 | + onWindowResize() { |
| 272 | + // Only handle resize for iOS card modals when no custom animations are provided |
| 273 | + if (getIonMode(this) !== 'ios' || !this.presentingElement || this.enterAnimation || this.leaveAnimation) { |
| 274 | + return; |
| 275 | + } |
| 276 | + |
| 277 | + clearTimeout(this.resizeTimeout); |
| 278 | + this.resizeTimeout = setTimeout(() => { |
| 279 | + this.handleViewTransition(); |
| 280 | + }, 50); // Debounce to avoid excessive calls during active resizing |
| 281 | + } |
| 282 | + |
271 | 283 | /** |
272 | 284 | * If `true`, the component passed into `ion-modal` will |
273 | 285 | * automatically be mounted when the modal is created. The |
@@ -983,16 +995,6 @@ export class Modal implements ComponentInterface, OverlayInterface { |
983 | 995 |
|
984 | 996 | // Set initial view state |
985 | 997 | this.currentViewIsPortrait = window.innerWidth < 768; |
986 | | - |
987 | | - // Create debounced resize handler |
988 | | - this.resizeListener = () => { |
989 | | - clearTimeout(this.resizeTimeout); |
990 | | - this.resizeTimeout = setTimeout(() => { |
991 | | - this.handleViewTransition(); |
992 | | - }, 50); // Debounce to avoid excessive calls during active resizing |
993 | | - }; |
994 | | - |
995 | | - window.addEventListener('resize', this.resizeListener); |
996 | 998 | } |
997 | 999 |
|
998 | 1000 | private handleViewTransition() { |
@@ -1048,11 +1050,6 @@ export class Modal implements ComponentInterface, OverlayInterface { |
1048 | 1050 | } |
1049 | 1051 |
|
1050 | 1052 | private cleanupViewTransitionListener() { |
1051 | | - if (this.resizeListener) { |
1052 | | - window.removeEventListener('resize', this.resizeListener); |
1053 | | - this.resizeListener = undefined; |
1054 | | - } |
1055 | | - |
1056 | 1053 | // Clear any pending resize timeout |
1057 | 1054 | if (this.resizeTimeout) { |
1058 | 1055 | clearTimeout(this.resizeTimeout); |
|
0 commit comments