From dc9faa6a0fbebb64c83c107c79cfd486cc0c096a Mon Sep 17 00:00:00 2001 From: Liam DeBeasi Date: Wed, 2 Dec 2020 15:44:34 -0500 Subject: [PATCH] fix(android): setting hardwareBackButton: false in config now disabled default webview behavior (#22555) resolves #18237 --- core/src/components/app/app.tsx | 7 +++++-- core/src/utils/hardware-back-button.ts | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/core/src/components/app/app.tsx b/core/src/components/app/app.tsx index 5f0734c7dc..e84ffbbaca 100644 --- a/core/src/components/app/app.tsx +++ b/core/src/components/app/app.tsx @@ -13,7 +13,7 @@ export class App implements ComponentInterface { componentDidLoad() { if (Build.isBrowser) { - rIC(() => { + rIC(async () => { const isHybrid = isPlatform(window, 'hybrid'); if (!config.getBoolean('_testing')) { import('../../utils/tap-click').then(module => module.startTapClick(config)); @@ -24,8 +24,11 @@ export class App implements ComponentInterface { if (config.getBoolean('inputShims', needInputShims())) { import('../../utils/input-shims/input-shims').then(module => module.startInputShims(config)); } + const hardwareBackButtonModule = await import('../../utils/hardware-back-button'); if (config.getBoolean('hardwareBackButton', isHybrid)) { - import('../../utils/hardware-back-button').then(module => module.startHardwareBackButton()); + hardwareBackButtonModule.startHardwareBackButton(); + } else { + hardwareBackButtonModule.blockHardwareBackButton(); } if (typeof (window as any) !== 'undefined') { import('../../utils/keyboard/keyboard').then(module => module.startKeyboardAssist(window)); diff --git a/core/src/utils/hardware-back-button.ts b/core/src/utils/hardware-back-button.ts index 1186783708..ef8a69def5 100644 --- a/core/src/utils/hardware-back-button.ts +++ b/core/src/utils/hardware-back-button.ts @@ -8,6 +8,20 @@ interface HandlerRegister { id: number; } +/** + * When hardwareBackButton: false in config, + * we need to make sure we also block the default + * webview behavior. If we don't then it will be + * possible for users to navigate backward while + * an overlay is still open. Additionally, it will + * give the appearance that the hardwareBackButton + * config is not working as the page transition + * will still happen. + */ +export const blockHardwareBackButton = () => { + document.addEventListener('backbutton', () => {}); // tslint:disable-line +} + export const startHardwareBackButton = () => { const doc = document;