-
Notifications
You must be signed in to change notification settings - Fork 661
feat(app): Add support for toggling Android back button handling #2390
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
Conversation
|
Released dev build of app with dev version: 7.0.3-dev-2390-20250902T150300.0 |
jcesarmobile
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding the this.onbackPressedCallback = callback; new line, set it on the callback creation changing OnBackPressedCallback callback = new OnBackPressedCallback(true) to this.onbackPressedCallback = new OnBackPressedCallback(true) (will also need to replace other usages of callback to this.onbackPressedCallback`
While this is supposed to enable the predictive back on Android 15+, this disables the back button handling for all Android versions, so I think that should be documented as for the current comment, it appears to only have an effect on Android 15+, but it affects all Android versions.
I don't fully understand what the "predictive back" is supposed to do, I see no difference on enabling it or disabling it, other than the back button handling not being into effect, which leads to the app being minimized instead of navigating back.
app/android/src/main/java/com/capacitorjs/plugins/app/AppPlugin.java
Outdated
Show resolved
Hide resolved
|
Also, I think this should be configurable from the capacitor config file to disable it from the beginning if desired, and the name should probably be about disabling back button handling as this is what the PR really does, which is required for predictive back to work, but you are disabling the back button handling in the end and people might want to use the app plugin just for the app information and not for the back button handling. |
I think you are right, especially the part about people may not wanting the back button handling from the plugin at all. I'll make those changes, and I'll keep the toggle as well (renaming it to be more generic) in case there are scenarios where devs want to temporarily enable / disable back button handling based on the state / routing of their app. |
jcesarmobile
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new configuration is not documented, you can add this to the README to get it generated automatically
## Configuration
<docgen-config>
</docgen-config>
or you can add it manually if the generation causes issues
app/android/src/main/java/com/capacitorjs/plugins/app/AppPlugin.java
Outdated
Show resolved
Hide resolved
app/package.json
Outdated
| "@capacitor/core": "^7.0.0", | ||
| "@capacitor/docgen": "0.2.2", | ||
| "@capacitor/ios": "^7.0.0", | ||
| "@capacitor/cli": "^7.0.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should go over @capacitor/core, if not it will be moved automatically in the future if some dependency gets installed or uninstalled
Adds a new configuration and runtime toggle for toggling on and off the App plugin's Android back button handling.
Disabling back button handling allows things like Android 13+ predictive back gesture to work.
closes: ionic-team/capacitor#6293