BackHandler doesn't work for tvos
See original GitHub issueWhen 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
- Use the following code in any component
componentDidMount() {
BackHandler.addEventListener("hardwareBackPress", this.handleBack);
}
handleBack = () => {
Alert.alert("It's a me, Mario");
};
- Press “menu” button on tvos
- 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:
- Created 4 years ago
- Comments:8

Top Related StackOverflow Question
It will work if you use the new
TVMenuControlmodule correctly. Look inRNTester/js/RNTesterApp.ios.jsin 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.
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-screensimplementation. 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.