question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BackHandler doesn't work for tvos

See original GitHub issue

When using the BackHandler as described in RNTester, the handler doesn’t work and menu button press causes to exit the app.

React Native version:

System: OS: macOS 10.14.6 CPU: (12) x64 Intel® Core™ i7-9750H CPU @ 2.60GHz Memory: 21.04 MB / 16.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 8.16.1 - /usr/local/bin/node npm: 6.4.1 - ~/n/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 12.4, macOS 10.14, tvOS 12.4, watchOS 5.3 IDEs: Android Studio: 3.4 AI-183.6156.11.34.5692245 Xcode: 10.3/10G8 - /usr/bin/xcodebuild npmPackages: react: 16.8.6 => 16.8.6 react-native: npm:react-native-tvos@0.60.4-6 => 0.60.4-6 npmGlobalPackages: react-native-cli: 2.0.1

Steps To Reproduce

  1. Use the following code in any component
  componentDidMount() {
    BackHandler.addEventListener("hardwareBackPress", this.handleBack);
  }
  handleBack = () => {
    Alert.alert("It's a me, Mario");
  };
  1. Press “menu” button on tvos
  2. App exits, instead of showing alert

Describe what you expected to happen: Cause alert to open and don’t exit the app.

Snack, code example, screenshot, or link to a repository: https://snack.expo.io/HkmBbUkOH

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8

github_iconTop GitHub Comments

2reactions
douglowdercommented, Sep 30, 2019

It will work if you use the new TVMenuControl module correctly. Look in RNTester/js/RNTesterApp.ios.js in the 0.60.4-6 branch to see the usage; the menu button should be enabled when pushing on the nav stack, and disabled when you get back to the bottom.

This module was added to satisfy Apple’s requirement that repeated menu button presses should bring the user to the home screen. Previously, RN apps for tvOS would permanently install a menu key gesture handler and prevent this from working.

0reactions
wouterdscommented, Oct 24, 2022

I see, thanks for clarifying. The thing that bothers me is that it does work for Android with this @react-navigation/native-stack & react-native-screens implementation. Would be nice if we could align that behaviour between tvOS & Android TV. The native navigation feels a lot more natural to me than the JS one and has some additional features which are handy that do not exist on the JS one. Would love to chat a bit more on this and help with implementing if possible.

Read more comments on GitHub >

github_iconTop Results From Across the Web

BackHandler doesn't work for tvos · Issue #18 - GitHub
When using the BackHandler as described in RNTester, the handler doesn't work and menu button press causes to exit the app.
Read more >
React Native TvOs - Short press on remote Menu Button ...
React Native TvOs - Short press on remote Menu Button doesn't fire BackHandler.exitApp(); to suspend the app. Is there any alternative?
Read more >
BackHandler - React Native
tvOS: Detect presses of the menu button on the TV remote. (Still to be implemented: programmatically disable menu button handling functionality ...
Read more >
useBackButton hook to handle back button behavior in React ...
useBackButton custom hook. To handle the behavior of hardware back button in Android and tvOS devices using React Native, there is BackHandler ......
Read more >
react-native-tvos - NPM Package Overview - Socket.dev
A framework for building native apps using React. Version: 0.69.6-0 was published by douglowder. Start using Socket to analyze ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found