fix(modal): keyboard listener removed on dismiss (#26856)

This commit is contained in:
Liam DeBeasi
2023-02-27 11:51:56 -05:00
committed by GitHub
parent 6dcd98b26a
commit b4bcba3533

View File

@ -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;
}
/**