question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: standard webview back nav seems to fire even when adding custom "backButton" listener via App plugin

See original GitHub issue

Bug 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:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
OoDeLallycommented, Feb 26, 2020

I had the same issue. You need to disable Ionic’s default handler: https://ionicframework.com/docs/angular/config Set hardwareBackButton to false.

1reaction
Mageek627commented, Jan 5, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

WebView and Android back button navigation - LogRocket Blog
Let's explore some solutions to common problems that Android developers often encounter when using WebView, such as back button navigation.
Read more >
Provide custom back navigation - Android Developers
Back navigation is how users move backward through the history of screens they previously visited. All Android devices provide a Back button for ......
Read more >
How to implement onBackPressed() in Fragments?
Implement the Backable interface in whichever fragment where you need to override the back button behavior. Add the implementation method. public class ...
Read more >
cordova-plugin-inappbrowser
The InAppBrowser window behaves like a standard web browser, and can't access Cordova APIs. For this reason, the InAppBrowser is recommended if you...
Read more >
WKWebView | Apple Developer Documentation
A web view offers control over the navigation and user experience through delegate objects. Use the navigation delegate to react when the user...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found