Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add experimental hardware back button support in browsers #28705

Merged
merged 9 commits into from
Jan 5, 2024

Conversation

liamdebeasi
Copy link
Contributor

@liamdebeasi liamdebeasi commented Dec 14, 2023

Issue number: resolves #28703


What is the current behavior?

Users are unable to dismiss modals and menus via the hardware back button in a mobile web browser/PWA.

What is the new behavior?

  • This PR adds a new feature that allows developers to leverage the CloseWatcher API. This enables hardware back button support in web browsers/PWAs.

Does this introduce a breaking change?

  • Yes
  • No

Other information

Dev build: 7.6.1-dev.11702569564.1746fa9f

Full design doc: https://github.com/ionic-team/ionic-framework-design-documents/pull/205

@github-actions github-actions bot added the package: core @ionic/core package label Dec 14, 2023
@@ -72,7 +72,32 @@ type IonicEvents = {
): void;
};

type IonicWindow = Window & IonicEvents;
export interface CloseWatcher extends EventTarget {
new (options?: CloseWatcherOptions): any;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having this return CloseWatcher gives me the following lint error:

/Users/liamdebeasi/Ionic/ionic/core/src/utils/browser/index.ts
  76:3  error  Interfaces cannot be constructed, only classes  @typescript-eslint/no-misused-new

✖ 1 problem (1 error, 0 warnings)

However, using any still gives us type checking:

[ ERROR ]  TypeScript: src/utils/hardware-back-button.ts:120:16
           Property 'liam' does not exist on type
           'CloseWatcher'.

    L119:   */
    L120:  watcher!.liam = true;
    L121:  watcher!.requestClose();

@liamdebeasi liamdebeasi marked this pull request as ready for review December 18, 2023 20:30
@@ -1,6 +1,7 @@
import type { ComponentInterface } from '@stencil/core';
import { Build, Component, Element, Host, Method, h } from '@stencil/core';
import type { FocusVisibleUtility } from '@utils/focus-visible';
import { shoudUseCloseWatcher } from '@utils/hardware-back-button';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still deciding if we should target Ionic 8 vs. Ionic 7.7. Anyone have strong feelings one way or the other?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No strong feelings since it's an opt-in feature. Maybe 7.7 b/c the sooner it comes out then the sooner the community can provide feedback if needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ Agreed.

core/src/utils/config.ts Show resolved Hide resolved
core/src/utils/config.ts Show resolved Hide resolved
core/src/utils/overlays.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@thetaPC thetaPC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@liamdebeasi liamdebeasi merged commit 658d1ca into feature-7.7 Jan 5, 2024
44 checks passed
@liamdebeasi liamdebeasi deleted the ld/close-watcher branch January 5, 2024 14:10
@liamdebeasi
Copy link
Contributor Author

Will put up docs in a separate PR

@a7medm7med
Copy link

@liamdebeasi @thetaPC @amandaejohnston

The CloseWatcher API, which was previously removed, is now back in Chromium version 126. I tested this feature and found it to work very well. However, there is an issue: when no overlays are present, I am unable to navigate back to the previous page. This seems to be a bug that needs to be addressed.

Ideally, the CloseWatcher API should only be active when overlays are present.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: core @ionic/core package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants