fix: overwritten backbutton not firing on first time by hardware button and never on back gesture#1910
fix: overwritten backbutton not firing on first time by hardware button and never on back gesture#1910GitToTheHub wants to merge 4 commits intomasterfrom
Conversation
…k gesture - When pressing the back button after the app starts nothing happens. When navigating to another page, the back button js event starts to fire. - On Android versions, which support the back gesture, nothing happens - This was due to the empty `OnBackPressedCallback.handleOnBackPressed` method, which has to forward its call to `cordova.getActivity().getOnBackPressedDispatcher().onBackPressed()`, but has to disable during this call the `backCallback`. - Generated-By: GPT-5.4, GitHub Copilot Chat
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1910 +/- ##
=======================================
Coverage 61.43% 61.43%
=======================================
Files 24 24
Lines 4922 4922
=======================================
Hits 3024 3024
Misses 1898 1898 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Fixes Android back handling when the Cordova back button is overridden, ensuring the JS backbutton event fires immediately after startup and also when back is triggered via the Android back gesture (OnBackPressedDispatcher path).
Changes:
- Implemented
OnBackPressedCallback.handleOnBackPressed()to actively dispatch a synthetic BACK key (DOWN+UP) through the Cordova WebView so existing key routing can fire the JSbackbuttonevent. - Added fallback to
OnBackPressedDispatcher.onBackPressed()when the WebView does not consume the synthetic key events, with temporary callback disabling to prevent recursion.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Hi @breautek, what are your thoughts about this PR? Is this ready to merge? |
…ackPressedCallback`` - The code moved to inline code
|
I made some code cleanup |
breautek
left a comment
There was a problem hiding this comment.
I don't have any beefs code wise. I'm trusting community feedback on functionality.
Platforms affected
Android
Motivation and Context
OnBackPressedCallback.handleOnBackPressedmethod, which has to forward its call to the WebView, which is done now by a synthetic back button event. If the WebView does not handle the synthetic back button event, the back button if forwarded tocordova.getActivity().getOnBackPressedDispatcher().onBackPressed().Code cleanup
registerBackPressedCallbackandunregisterBackPressedCallback. The code moved to inline code.Description
Testing
Checklist
(platform)if this change only applies to one platform (e.g.(android))