mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
fix(): handle failure in hardware back button
This commit is contained in:
2
core/src/components.d.ts
vendored
2
core/src/components.d.ts
vendored
@@ -4019,7 +4019,7 @@ export namespace Components {
|
||||
* The text to display on the ok button. Default: `OK`.
|
||||
*/
|
||||
'okText': string;
|
||||
'open': (ev?: UIEvent | undefined) => Promise<HTMLIonActionSheetElement | HTMLIonAlertElement | HTMLIonPopoverElement>;
|
||||
'open': (ev?: UIEvent | undefined) => Promise<HTMLIonPopoverElement | HTMLIonActionSheetElement | HTMLIonAlertElement>;
|
||||
/**
|
||||
* The text to display when the select is empty.
|
||||
*/
|
||||
|
||||
@@ -81,7 +81,7 @@ export class Router {
|
||||
return this.writeNavStateRoot(path, direction);
|
||||
}
|
||||
|
||||
@Listen('window:ionBackButton')
|
||||
@Listen('document:ionBackButton')
|
||||
protected onBackButton(ev: BackButtonEvent) {
|
||||
ev.detail.register(0, () => this.goBack());
|
||||
}
|
||||
|
||||
@@ -9,11 +9,11 @@ interface HandlerRegister {
|
||||
|
||||
export function startHardwareBackButton(win: Window) {
|
||||
let busy = false;
|
||||
win.addEventListener('backbutton', () => {
|
||||
win.document.addEventListener('backbutton', () => {
|
||||
if (busy) {
|
||||
return;
|
||||
}
|
||||
busy = true;
|
||||
|
||||
const handlers: HandlerRegister[] = [];
|
||||
const ev: BackButtonEvent = new CustomEvent('ionBackButton', {
|
||||
bubbles: false,
|
||||
@@ -23,9 +23,10 @@ export function startHardwareBackButton(win: Window) {
|
||||
}
|
||||
}
|
||||
});
|
||||
win.document.body.dispatchEvent(ev);
|
||||
win.document.dispatchEvent(ev);
|
||||
|
||||
if (handlers.length > 0) {
|
||||
busy = true;
|
||||
let selectedPriority = Number.MIN_SAFE_INTEGER;
|
||||
let handler: Handler;
|
||||
handlers.forEach(h => {
|
||||
@@ -34,9 +35,15 @@ export function startHardwareBackButton(win: Window) {
|
||||
handler = h.handler;
|
||||
}
|
||||
});
|
||||
const result = handler!();
|
||||
if (result != null) {
|
||||
result.then(() => busy = false);
|
||||
try {
|
||||
const result = handler!();
|
||||
if (result != null) {
|
||||
result.then(() => (busy = false), () => (busy = false));
|
||||
} else {
|
||||
busy = false;
|
||||
}
|
||||
} catch (ev) {
|
||||
busy = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -19,7 +19,7 @@ export function createOverlay<T extends HTMLIonOverlayElement>(element: T, opts:
|
||||
// append the overlay element to the document body
|
||||
getAppRoot(doc).appendChild(element);
|
||||
|
||||
doc.body.addEventListener('ionBackButton', ev => {
|
||||
doc.addEventListener('ionBackButton', ev => {
|
||||
(ev as BackButtonEvent).detail.register(100, () => closeTopOverlay(doc));
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user