feat(core): back button event on Android, closes #8142 - #19
Conversation
Greptile SummaryThis PR implements Android back button event handling, allowing developers to listen for back button presses via the new Key Changes:
Implementation Details:
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant Android
participant AppPlugin
participant WebView
participant JS_API
participant EventListener
User->>Android: Press Back Button
Android->>AppPlugin: OnBackPressedCallback.handleOnBackPressed()
alt Has Event Listener Registered
AppPlugin->>AppPlugin: hasListener("back-button")
AppPlugin->>WebView: Check canGoBack()
WebView-->>AppPlugin: Return canGoBack status
AppPlugin->>EventListener: trigger("back-button", {canGoBack})
EventListener->>JS_API: onBackButtonPress handler
JS_API-->>User: Custom handling (developer defined)
else No Event Listener
alt WebView Can Navigate Back
AppPlugin->>WebView: canGoBack() == true
AppPlugin->>WebView: goBack()
WebView-->>User: Navigate to previous page
else WebView Cannot Navigate Back
AppPlugin->>AppPlugin: Disable callback temporarily
AppPlugin->>Android: activity.onBackPressed()
Android-->>User: System back behavior (exit app)
AppPlugin->>AppPlugin: Re-enable callback
end
end
|
| this@AppPlugin.webView!!.goBack() | ||
| } else { | ||
| this.isEnabled = false | ||
| this@AppPlugin.activity.onBackPressed() |
There was a problem hiding this comment.
syntax: activity.onBackPressed() is deprecated in Android API 33+
Suggested change
| this@AppPlugin.activity.onBackPressed() | |
| (this@AppPlugin.activity as? androidx.activity.ComponentActivity)?.onBackPressedDispatcher?.onBackPressed() |
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/tauri/mobile/android/src/main/java/app/tauri/AppPlugin.kt
Line: 35:35
Comment:
**syntax:** `activity.onBackPressed()` is deprecated in Android API 33+
```suggestion
(this@AppPlugin.activity as? androidx.activity.ComponentActivity)?.onBackPressedDispatcher?.onBackPressed()
```
How can I resolve this? If you propose a fix, please make it concise.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Benchmark PR from qodo-benchmark#162