|
|
@ -60,6 +60,29 @@ export function useHardwareBackHandler( |
|
|
}, [enabled]); |
|
|
}, [enabled]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Synchronously invokes the topmost hardware-back handler if registered. |
|
|
|
|
|
* Returns true if a handler consumed the event, or false if Flutter should handle/close. |
|
|
|
|
|
*/ |
|
|
|
|
|
export function handleHardwareBackSync(): boolean { |
|
|
|
|
|
if (backHandlerStack.length === 0) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const handler = backHandlerStack[backHandlerStack.length - 1]; |
|
|
|
|
|
try { |
|
|
|
|
|
const result = handler(); |
|
|
|
|
|
if (result instanceof Promise) { |
|
|
|
|
|
// Promise was initiated by invoking the handler; it is handled in JS!
|
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
return Boolean(result); |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
console.warn("[HardwareBackSync] Handler threw:", error); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Called by the root bootstrap script when Flutter sends a hardware back event. |
|
|
* Called by the root bootstrap script when Flutter sends a hardware back event. |
|
|
* Returns { handled: true } if a web handler consumed the event, or |
|
|
* Returns { handled: true } if a web handler consumed the event, or |
|
|
@ -74,7 +97,7 @@ export async function handleHardwareBack(): Promise<{ handled: boolean }> { |
|
|
const handler = backHandlerStack[backHandlerStack.length - 1]; |
|
|
const handler = backHandlerStack[backHandlerStack.length - 1]; |
|
|
try { |
|
|
try { |
|
|
const result = await handler(); |
|
|
const result = await handler(); |
|
|
return { handled: result }; |
|
|
|
|
|
|
|
|
return { handled: Boolean(result) }; |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
console.warn("[HardwareBack] Handler threw:", error); |
|
|
console.warn("[HardwareBack] Handler threw:", error); |
|
|
return { handled: false }; |
|
|
return { handled: false }; |
|
|
|