react / react/react-native

[Android] BackHandler receives no events on API 35 with predictive Back enabled

オープン
#58,407 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

API: BackHandler Needs: Triage :mag: Platform: Android
主要言語
C++
スター
127k
フォーク
25.3k
平均マージ
1日 23時間
マージ済み PR(30日)
4

説明

Description

With android:enableOnBackInvokedCallback="true", a minimal bare React Native application does not deliver hardwareBackPress to JavaScript on Android API 35.

The app has one BackHandler listener that logs hardwareBackPress received, increments a visible counter, and returns true.

Observed on a Pixel 8 Pro emulator / Android API 35: pressing the system navigation-bar Back button leaves Back count: 0, emits no hardwareBackPress received log, and returns Android to the home screen.

The reproduction uses React Native 0.87.1.

Control result

Using the same React Native 0.87.1 application and device configuration, with no other source changes, changing only android:enableOnBackInvokedCallback from true to false makes hardwareBackPress reach JavaScript: Back count increments and the app remains visible.

Related reports checked

  • #51349: similar symptom, originally reported on RN 0.75.1 without a reproducer. The author later reported that the issue no longer occurred after upgrading to RN 0.79.2. In the original report, setting enableOnBackInvokedCallback=false did not resolve the problem.

  • #34529: broader discussion about migrating React Native's Back handling to the APIs used by predictive Back. The API 35 behavior reported here may be another manifestation of the same underlying migration gap.

  • #54887: reports BackHandler stopping after the app returns from the background on API 36+. In this reproduction, the failure occurs on the first Back press after launch. The RN 0.86 release notes also list a fix for BackHandler callbacks after app resume on API 36+.

  • expo/expo#39092: reports broken Expo Router stack navigation with predictive Back enabled and is labeled Upstream: React Native Screens. The reproduction here contains no Expo, navigation library, or react-native-screens dependency.

  • react-native-screens discussion #2540: primarily discusses predictive Back support for Fragment-based navigation. Later comments also describe BackHandler failures after app resume with target SDK 36.

Expo relevance

Expo's android.predictiveBackGestureEnabled: true maps to android:enableOnBackInvokedCallback=true in the generated Android manifest. This reproduction does not include Expo, so Expo-specific behavior was not tested; however, Expo bare apps using that setting may be affected by the same native configuration.

Steps to reproduce
  1. Clone https://github.com/DanyKrk/android-backhandler-api35-repro

  2. Install dependencies and start Metro:

     cd ReproducerApp
     corepack yarn install --frozen-lockfile
     corepack yarn start
    
  3. In another terminal, build and install the debug APK:

      cd ReproducerApp/android
      ./gradlew :app:assembleDebug
      adb install -r app/build/outputs/apk/debug/app-debug.apk
    
  4. Use a Pixel 8 Pro emulator running Android API 35.

  5. Open the app and press the system navigation-bar Back button.

Expected: hardwareBackPress reaches the listener, Back count increments, and the app remains visible.

Actual: Back count remains 0; no hardwareBackPress received log is emitted; Android returns to the home screen.

React Native Version

0.87.1

Affected Platforms

Runtime - Android, Build - MacOS

Output of npx @react-native-community/cli info
info Fetching system and libraries information...
System:
  OS: macOS 26.6.2
  CPU: (14) arm64 Apple M4 Pro
  Memory: 192.94 MB / 24.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 24.14.0
    path: $HOME/.local/share/mise/installs/node/lts/bin/node
  Yarn:
    version: 1.22.22
    path: $HOME/.local/share/mise/installs/node/lts/bin/yarn
  npm:
    version: 11.9.0
    path: $HOME/.local/share/mise/installs/node/lts/bin/npm
  Watchman:
    version: 2026.06.08.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.1
    path: $HOME/.local/share/mise/installs/ruby/3.2/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 25.5
      - iOS 26.5
      - macOS 26.5
      - tvOS 26.5
      - visionOS 26.5
      - watchOS 26.5
  Android SDK: Not Found
IDEs:
  Android Studio: 2026.1 AI-261.26222.65.2613.16025427
  Xcode:
    version: 26.6/17F113
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.18
    path: $HOME/.local/share/mise/installs/java/temurin-17/bin/javac
  Ruby:
    version: 3.2.11
    path: $HOME/.local/share/mise/installs/ruby/3.2/bin/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 20.2.0
    wanted: 20.2.0
  react:
    installed: 19.2.3
    wanted: 19.2.3
  react-native:
    installed: 0.87.1
    wanted: 0.87.1
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: false
Stacktrace or Logs
No stack trace exists. This is not reported as a crash or process termination.

  The app registers this listener:

  BackHandler.addEventListener('hardwareBackPress', () => {
    console.log('hardwareBackPress received');
    setBackCount(count => count + 1);
    return true;
  });

  Observed on a Pixel 8 Pro emulator / Android API 35:
  - React Native: 0.87.1
  - target SDK: 36
  - android:enableOnBackInvokedCallback: true
  - Input: system navigation-bar Back button

  Expected JS log:
  hardwareBackPress received

  Actual:
  No `hardwareBackPress received` log is emitted because the
  `hardwareBackPress` listener is not invoked.
  `Back count` remains 0 and Android returns to the home screen.
MANDATORY Reproducer

https://github.com/DanyKrk/android-backhandler-api35-repro

Screenshots and Videos

https://github.com/user-attachments/assets/02e39d73-6f93-4659-ac74-002daed55eb9

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、Android API 35 と React Native 0.87.1 を搭載した Pixel 8 Pro エミュレーターで、必須の android-backhandler-api35-repro を実行します。enableOnBackInvokedCallback を true と false に設定した場合の BackHandler リスナーの動作を比較します。true の設定で hardwareBackPress が発生し、Back count がインクリメントされ、アプリが表示されたままになれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
android, javascript
領域
mobile-dev
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
活発
明瞭さ
おおむね明確
初心者へのやさしさ
58/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。