bug: standard webview back nav seems to fire even when adding custom "backButton" listener via App plugin
See original GitHub issueBug Report
Capacitor Version
Ionic Framework : ionic-angular 3.9.2 @ionic/app-scripts : 3.2.2 NodeJS: v11.7.0 npm: 6.5.0 OS: macOS Mojave
npx cap doctor
output:
Latest Dependencies: @capacitor/cli: 1.3.0 @capacitor/core: 1.3.0 @capacitor/android: 1.3.0 @capacitor/ios: 1.3.0
Installed Dependencies: @capacitor/cli 1.3.0 @capacitor/core 1.3.0 @capacitor/ios 1.3.0 @capacitor/android 1.3.0
[success] Android looking great! 👌 Found 4 Capacitor plugins for ios: cordova-plugin-nativeaudio (3.1.1) cordova-plugin-screen-orientation (3.0.2) cordova-sqlite-storage (2.4.0) es6-promise-plugin (4.2.2) [success] iOS looking great! 👌
Affected Platform(s)
- Android
- iOS
- Electron
- Web
Current Behavior
When adding a ‘backButton’ listener to the App plugin to override the hardware back button behaviour, the listener is notified, but the original back button functionality still fires, so it’s only possible to add to this functionality, not override it entirely.
Expected Behavior
In com.getcapacitor.Bridge.java’s onBackPressed
method, there is a comment that suggests that the default action shouldn’t be executed if the user has added a back button listener:
// If there are listeners, don’t do the default action, as this means the user // wants to override the back button
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:6 (2 by maintainers)
Top GitHub Comments
I had the same issue. You need to disable Ionic’s default handler: https://ionicframework.com/docs/angular/config Set
hardwareBackButton
tofalse
.See https://github.com/ionic-team/capacitor/issues/1457
I agree that the documentation should be way way clearer than what it currently is if we want it to be usable. Way too much googling is needed for something as simple as handling back button.