mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-09 16:16:41 +08:00
fix(modal): keyboard listener removed on dismiss (#26856)
This commit is contained in:
@ -333,7 +333,7 @@ export class Modal implements ComponentInterface, OverlayInterface {
|
||||
if (this.gesture) {
|
||||
this.gesture.enable(enable);
|
||||
} else if (enable) {
|
||||
await this.initSwipeToClose();
|
||||
this.initSwipeToClose();
|
||||
}
|
||||
}
|
||||
|
||||
@ -532,6 +532,38 @@ export class Modal implements ComponentInterface, OverlayInterface {
|
||||
backdropBreakpoint: this.backdropBreakpoint,
|
||||
});
|
||||
|
||||
/* tslint:disable-next-line */
|
||||
if (typeof window !== 'undefined') {
|
||||
/**
|
||||
* This needs to be setup before any
|
||||
* non-transition async work so it can be dereferenced
|
||||
* in the dismiss method. The dismiss method
|
||||
* only waits for the entering transition
|
||||
* to finish. It does not wait for all of the `present`
|
||||
* method to resolve.
|
||||
*/
|
||||
this.keyboardOpenCallback = () => {
|
||||
if (this.gesture) {
|
||||
/**
|
||||
* When the native keyboard is opened and the webview
|
||||
* is resized, the gesture implementation will become unresponsive
|
||||
* and enter a free-scroll mode.
|
||||
*
|
||||
* When the keyboard is opened, we disable the gesture for
|
||||
* a single frame and re-enable once the contents have repositioned
|
||||
* from the keyboard placement.
|
||||
*/
|
||||
this.gesture.enable(false);
|
||||
raf(() => {
|
||||
if (this.gesture) {
|
||||
this.gesture.enable(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
window.addEventListener(KEYBOARD_DID_OPEN, this.keyboardOpenCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO (FW-937) - In the next major release of Ionic, all card modals
|
||||
* will be swipeable by default. canDismiss will be used to determine if the
|
||||
@ -559,31 +591,7 @@ export class Modal implements ComponentInterface, OverlayInterface {
|
||||
if (this.isSheetModal) {
|
||||
this.initSheetGesture();
|
||||
} else if (hasCardModal) {
|
||||
await this.initSwipeToClose();
|
||||
}
|
||||
|
||||
/* tslint:disable-next-line */
|
||||
if (typeof window !== 'undefined') {
|
||||
this.keyboardOpenCallback = () => {
|
||||
if (this.gesture) {
|
||||
/**
|
||||
* When the native keyboard is opened and the webview
|
||||
* is resized, the gesture implementation will become unresponsive
|
||||
* and enter a free-scroll mode.
|
||||
*
|
||||
* When the keyboard is opened, we disable the gesture for
|
||||
* a single frame and re-enable once the contents have repositioned
|
||||
* from the keyboard placement.
|
||||
*/
|
||||
this.gesture.enable(false);
|
||||
raf(() => {
|
||||
if (this.gesture) {
|
||||
this.gesture.enable(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
window.addEventListener(KEYBOARD_DID_OPEN, this.keyboardOpenCallback);
|
||||
this.initSwipeToClose();
|
||||
}
|
||||
|
||||
this.currentTransition = undefined;
|
||||
@ -725,6 +733,7 @@ export class Modal implements ComponentInterface, OverlayInterface {
|
||||
/* tslint:disable-next-line */
|
||||
if (typeof window !== 'undefined' && this.keyboardOpenCallback) {
|
||||
window.removeEventListener(KEYBOARD_DID_OPEN, this.keyboardOpenCallback);
|
||||
this.keyboardOpenCallback = undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user