Skip to content

feat(core): back button event on Android, closes #8142 - #19

Open
tomerqodo wants to merge 2 commits into
greptile_combined_20260121_qodo_grep_cursor_copilot_1_base_featcore_back_button_event_on_android_closes_8142_pr162from
greptile_combined_20260121_qodo_grep_cursor_copilot_1_head_featcore_back_button_event_on_android_closes_8142_pr162
Open

feat(core): back button event on Android, closes #8142#19
tomerqodo wants to merge 2 commits into
greptile_combined_20260121_qodo_grep_cursor_copilot_1_base_featcore_back_button_event_on_android_closes_8142_pr162from
greptile_combined_20260121_qodo_grep_cursor_copilot_1_head_featcore_back_button_event_on_android_closes_8142_pr162

Conversation

@tomerqodo

Copy link
Copy Markdown

Benchmark PR from qodo-benchmark#162

@greptile-apps

greptile-apps Bot commented Jan 21, 2026

Copy link
Copy Markdown

Greptile Summary

This PR implements Android back button event handling, allowing developers to listen for back button presses via the new onBackButtonPress API. When no listener is registered, the default behavior provides automatic webview history navigation or app exit.

Key Changes:

  • Added AppPlugin.kt for Android that intercepts back button presses using OnBackPressedCallback
  • Created TypeScript API onBackButtonPress that provides canGoBack status to event handlers
  • Integrated Android plugin registration in Rust app plugin setup
  • Updated wry dependency to 0.53.4
  • Added permission entries for register_listener and remove_listener commands

Implementation Details:

  • When a listener is registered, the plugin triggers a back-button event with webview navigation state
  • Without a listener, the plugin automatically handles webview back navigation or delegates to system back behavior
  • The exit() command is exposed in Kotlin but not currently exported in the TypeScript API

Confidence Score: 4/5

  • This PR is mostly safe to merge with one minor deprecation issue
  • The implementation is well-structured and follows Tauri patterns correctly. The TypeScript API is properly typed and documented. However, the use of the deprecated activity.onBackPressed() method in AppPlugin.kt should be addressed before merging to avoid issues with newer Android API levels (33+).
  • Pay attention to crates/tauri/mobile/android/src/main/java/app/tauri/AppPlugin.kt due to deprecated API usage

Important Files Changed

Filename Overview
crates/tauri/mobile/android/src/main/java/app/tauri/AppPlugin.kt New AppPlugin for back button handling with exit command; uses deprecated activity.onBackPressed() method
crates/tauri/mobile/android-codegen/TauriActivity.kt Added handleBackNavigation property to enable back button handling in generated TauriActivity
packages/api/src/app.ts Added TypeScript API for onBackButtonPress event listener with proper types and documentation
crates/tauri/src/app/plugin.rs Registered Android AppPlugin and added register/remove listener commands to the app plugin

Sequence Diagram

sequenceDiagram
    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
Loading

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

this@AppPlugin.webView!!.goBack()
} else {
this.isEnabled = false
this@AppPlugin.activity.onBackPressed()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant