mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 19:21:34 +08:00
refactor(back-button): handle busy state better
This commit is contained in:
@ -26,25 +26,30 @@ export function startHardwareBackButton(win: Window) {
|
|||||||
win.document.dispatchEvent(ev);
|
win.document.dispatchEvent(ev);
|
||||||
|
|
||||||
if (handlers.length > 0) {
|
if (handlers.length > 0) {
|
||||||
busy = true;
|
|
||||||
let selectedPriority = Number.MIN_SAFE_INTEGER;
|
let selectedPriority = Number.MIN_SAFE_INTEGER;
|
||||||
let handler: Handler;
|
let handler: Handler | undefined;
|
||||||
handlers.forEach(h => {
|
handlers.forEach(h => {
|
||||||
if (h.priority >= selectedPriority) {
|
if (h.priority >= selectedPriority) {
|
||||||
selectedPriority = h.priority;
|
selectedPriority = h.priority;
|
||||||
handler = h.handler;
|
handler = h.handler;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
try {
|
|
||||||
const result = handler!();
|
busy = true;
|
||||||
if (result != null) {
|
executeAction(handler).then(() => busy = false);
|
||||||
result.then(() => (busy = false), () => (busy = false));
|
|
||||||
} else {
|
|
||||||
busy = false;
|
|
||||||
}
|
|
||||||
} catch (ev) {
|
|
||||||
busy = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function executeAction(handler: Handler | undefined) {
|
||||||
|
try {
|
||||||
|
if (handler) {
|
||||||
|
const result = handler();
|
||||||
|
if (result) {
|
||||||
|
await result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user