Skip to content

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

Open
tomerqodo wants to merge 2 commits into
greptile_full_base_featcore_back_button_event_on_android_closes_8142_pr6from
greptile_full_head_featcore_back_button_event_on_android_closes_8142_pr6
Open

tomerqodo wants to merge 2 commits into
greptile_full_base_featcore_back_button_event_on_android_closes_8142_pr6from
greptile_full_head_featcore_back_button_event_on_android_closes_8142_pr6

Conversation

@tomerqodo

Copy link
Copy Markdown

Benchmark PR from agentic-review-benchmarks#6

@greptile-apps

greptile-apps Bot commented Jan 26, 2026

Copy link
Copy Markdown

Greptile Overview

Greptile Summary

Implements Android back button event handling by creating a new AppPlugin for Android that intercepts back button presses and provides a TypeScript API (onBackButtonPress) for custom handling.

Key changes:

  • Added AppPlugin.kt with back button callback that checks for listeners and either triggers custom event or performs default navigation (webview history or app exit)
  • Exposed onBackButtonPress event listener in TypeScript API with canGoBack payload
  • Registered plugin in Rust app plugin system with proper Android integration
  • Added hasListener utility method to Plugin.kt base class
  • Updated permissions system to include register_listener and remove_listener commands
  • Bumped wry dependency from 0.53.2 to 0.53.4

Issues found:

  • Critical logic issue in AppPlugin.kt:31-32 where null-safety check is followed by non-null assertion operator that can still throw NPE

Confidence Score: 3/5

  • PR has one critical null-safety issue that could cause runtime crashes on Android
  • The implementation is well-structured with proper TypeScript/Rust/Kotlin integration, but contains a critical null-pointer exception risk in the back button handler. The null-safety issue in AppPlugin.kt line 31-32 needs to be fixed before merge to prevent potential crashes.
  • Pay close attention to crates/tauri/mobile/android/src/main/java/app/tauri/AppPlugin.kt for the null-safety issue

Important Files Changed

Filename Overview
crates/tauri/mobile/android/src/main/java/app/tauri/AppPlugin.kt Implements Android back button event handling with listener support and exit command
packages/api/src/app.ts Adds TypeScript API for back button press event with proper type definitions
crates/tauri/src/app/plugin.rs Registers Android AppPlugin in the Rust plugin system
crates/tauri/mobile/android/src/main/java/app/tauri/plugin/Plugin.kt Adds hasListener utility method for checking event listeners, removes unused imports
crates/tauri/mobile/android-codegen/TauriActivity.kt Sets handleBackNavigation to true, enabling custom back button handling

Sequence Diagram

sequenceDiagram
    participant User
    participant AndroidOS
    participant TauriActivity
    participant AppPlugin
    participant WebView
    participant JSApp
    
    User->>AndroidOS: Presses back button
    AndroidOS->>TauriActivity: onBackPressed event
    TauriActivity->>AppPlugin: handleOnBackPressed callback
    
    alt Has back-button event listener
        AppPlugin->>WebView: Check canGoBack()
        WebView-->>AppPlugin: canGoBack status
        AppPlugin->>JSApp: Trigger 'back-button' event with {canGoBack}
        JSApp->>JSApp: Execute custom handler
    else No listener registered
        AppPlugin->>WebView: Check canGoBack()
        WebView-->>AppPlugin: true
        AppPlugin->>WebView: goBack()
        WebView->>WebView: Navigate to previous page
    else No listener and cannot go back
        AppPlugin->>AppPlugin: Disable callback temporarily
        AppPlugin->>TauriActivity: activity.onBackPressed()
        TauriActivity->>AndroidOS: Default back behavior (exit app)
        AppPlugin->>AppPlugin: Re-enable callback
    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.

2 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +31 to +32
if (this@AppPlugin.webView?.canGoBack() == true) {
this@AppPlugin.webView!!.goBack()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

null-safety check followed by non-null assertion (!!) can still throw NPE if webView becomes null between the check and the call

Suggested change
if (this@AppPlugin.webView?.canGoBack() == true) {
this@AppPlugin.webView!!.goBack()
this@AppPlugin.webView?.goBack()
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: 31:32

Comment:
null-safety check followed by non-null assertion (`!!`) can still throw NPE if webView becomes null between the check and the call

```suggestion
            this@AppPlugin.webView?.goBack()
```

How can I resolve this? If you propose a fix, please make it concise.


abstract class TauriActivity : WryActivity() {
var pluginManager: PluginManager = PluginManager(this)
override val handleBackNavigation: Boolean = true

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

verify that WryActivity defines handleBackNavigation as an overridable property - if not defined in the parent class, this will cause a compilation error

Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/tauri/mobile/android-codegen/TauriActivity.kt
Line: 15:15

Comment:
verify that `WryActivity` defines `handleBackNavigation` as an overridable property - if not defined in the parent class, this will cause a compilation error

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