react-native icon indicating copy to clipboard operation
react-native copied to clipboard

BackHandler Does Not Work Google Pixel

Open enchorb opened this issue 1 year ago • 7 comments

Description

More detail: https://github.com/react-navigation/react-navigation/issues/11227

It seems on Google Pixel devices the BackHandler does not work

Steps to reproduce

Use back handler on Google Pixel 6+ device

React Native Version

0.74

Affected Platforms

Runtime - Android

Output of npx react-native info

System:
  OS: Windows 10 10.0.19045
  CPU: (20) x64 Intel(R) Core(TM) i9-10850K CPU @ 3.60GHz
  Memory: 64.71 GB / 127.92 GB
Binaries:
  Node:
    version: 20.13.1
    path: C:\Program Files\nodejs\node.EXE
  Yarn:
    version: 4.2.1
    path: C:\Program Files\nodejs\yarn.CMD
  npm:
    version: 10.5.2
    path: C:\Program Files\nodejs\npm.CMD
  Watchman: Not Found
SDKs:
  Android SDK:
    API Levels:
      - "29"
      - "31"
      - "33"
      - "34"
    Build Tools:
      - 30.0.2
      - 30.0.3
      - 31.0.0
      - 32.0.0
      - 33.0.0
      - 33.0.1
      - 34.0.0
      - 35.0.0
    System Images:
      - android-29 | Google Play Intel x86 Atom
      - android-30 | Google Play Intel x86 Atom
      - android-31 | Google Play Intel x86_64 Atom
      - android-33 | Google Play Intel x86_64 Atom
      - android-34 | Google APIs Intel x86_64 Atom
    Android NDK: Not Found
  Windows SDK:
    AllowAllTrustedApps: Enabled
    AllowDevelopmentWithoutDevLicense: Enabled
    Versions:
      - 10.0.17763.0
IDEs:
  Android Studio: Not Found
  Visual Studio: Not Found
Languages:
  Java: 17.0.11
  Ruby: Not Found
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.73.8
    wanted: 0.73.8
  react-native-windows: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: Not found
  newArchEnabled: Not found
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

Stacktrace or Logs

N/A

Reproducer

https://github.com/Roamer77/Android13backButtonBug

Screenshots and Videos

No response

enchorb avatar May 24 '24 11:05 enchorb

:warning: Add or Reformat Version Info
:information_source: We could not find or parse the version number of React Native in your issue report. Please use the template, and report your version including major, minor, and patch numbers - e.g. 0.70.2

github-actions[bot] avatar May 24 '24 11:05 github-actions[bot]

:warning: Missing Reproducible Example
:information_source: We could not detect a reproducible example in your issue report. Please provide either:
  • If your bug is UI related: a Snack
  • If your bug is build/update related: use our Reproducer Template. A reproducer needs to be in a GitHub repository under your username.

github-actions[bot] avatar May 24 '24 11:05 github-actions[bot]

It seems on Google Pixel devices the BackHandler does not work

A couple of questions:

  1. Can you clarify what you mean with "BackHandler" here?
  2. Can you point to the code in your reproducer where you're managing the back gesture?
  3. Can you provide a video of the currect/expected behavior.

Please answer all of them and we'll be able to investigate further

cortinico avatar Jun 04 '24 12:06 cortinico

This issue is waiting for author's feedback since 24 days. Please provide the requested feedback or this will be closed in 7 days.

github-actions[bot] avatar Jun 29 '24 05:06 github-actions[bot]

@cortinico To answer your questions:

  1. By BackHandler, I'm referring to handling the Android back button. When using React Navigation on non-Pixel devices, when the hardware back button is pressed it navigates to the previous screen. On Pixel devices it just closes the app.

  2. https://github.com/Roamer77/Android13backButtonBug (to test you can you the Android emulator or actual device). Any Pixel version works, I tested on Pixel 7 Pro API 34 & Pixel 6.

  3. Not shown in the video, on the Android emulator pressed the hardware back button

Screen_recording_20240704_101748.webm

enchorb avatar Jul 04 '24 14:07 enchorb

@cortinico To answer your questions:

  1. By BackHandler, I'm referring to handling the Android back button. When using React Navigation on non-Pixel devices, when the hardware back button is pressed it navigates to the previous screen. On Pixel devices it just closes the app.
  2. https://github.com/Roamer77/Android13backButtonBug (to test you can you the Android emulator or actual device). Any Pixel version works, I tested on Pixel 7 Pro API 34 & Pixel 6.
  3. Not shown in the video, on the Android emulator pressed the hardware back button

Screen_recording_20240704_101748.webm

I double checked on other devices. The same is happening on my app. It just closes the app and is not only tight to pixel devices. It is the android version operating it. In my case i used android version 14 to test. On Api 29 it still works so its a mix of android change and react native update.

ImBeCiliC avatar Aug 21 '24 11:08 ImBeCiliC

I have used the backhandler on my device pixel 5 and face this issue still. @ImBeCiliC

usmanabid94 avatar Oct 23 '24 17:10 usmanabid94

Same here on Samsung devices on RN 0.74.1.

I suspect the issue is somehow related to the api changes talked about here: https://github.com/facebook/react-native/issues/34529

I can confirm it still works on Android 10 and breaks on Android 14. The linked issue suggests it might breaks with Android 13.

There also seems to be a temporary workaround: https://github.com/react-navigation/react-navigation/issues/11227#issuecomment-2307023740

EDIT: Expo users can use this config plugin to apply the workaround:

const withTempFixAndroidBackButton: ConfigPlugin = (config) => {
  return withAndroidManifest(config, (config) => {
    AndroidConfig.Manifest.getMainActivityOrThrow(config.modResults).$["android:enableOnBackInvokedCallback"] = "false";
    return config;
  });
};

mauricedoepke avatar Dec 17 '24 13:12 mauricedoepke

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

react-native-bot avatar Jun 16 '25 05:06 react-native-bot