react-native: Apple TV react-native doesn't follow Apple's tvOS guidelines for menu key behavior
- I have reviewed the documentation
- I have searched existing issues
- I am using the latest React Native version
When running a react-native app built for tvOS, the remote control’s menu key does not exit the app and return to the tvOS home screen, as required by Apple. See guidelines at https://developer.apple.com/tvos/human-interface-guidelines/remote-and-controllers/remote/
This is happening because the RCTTVRemoteHandler class is adding a menu key gesture recognizer by default to RCTRootView. The gesture recognizer should be added if a screen is pushed onto a navigation stack and we are navigating back to a lower level screen; it should not be added for the app’s main view.
Environment
Environment: OS: macOS High Sierra 10.13.4 Node: 8.9.1 Yarn: 1.5.1 npm: 5.5.1 Watchman: Not Found Xcode: Xcode 9.3 Build version 9E145 Android Studio: 3.1 AI-173.4697961
Packages: (wanted => installed) react: ^16.0.0 => 16.3.2 react-native: ^0.54.0 => 0.54.4
Steps to Reproduce
See issue description above – the same thing happens on both tvOS simulator and a real tvOS device.
Expected Behavior
Menu key should exit the app as required. For apps that use navigation frameworks that back-navigate using menu key, the correct behavior needs to be implemented.
Actual Behavior
See description above.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 2
- Comments: 15 (3 by maintainers)
Commits related to this issue
- Correct Apple TV menu key behavior (fix RN issue https://github.com/facebook/react-native/issues/18930) — committed to react-native-tvos/react-native-tvos by douglowder 5 years ago
- Correct Apple TV menu key behavior (fix RN issue https://github.com/facebook/react-native/issues/18930) — committed to react-native-tvos/react-native-tvos by douglowder 5 years ago
- Correct Apple TV menu key behavior (fix RN issue https://github.com/facebook/react-native/issues/18930) — committed to react-native-tvos/react-native-tvos by douglowder 5 years ago
- Correct Apple TV menu key behavior (fix RN issue https://github.com/facebook/react-native/issues/18930) — committed to react-native-tvos/react-native-tvos by douglowder 5 years ago
- Correct Apple TV menu key behavior (fix RN issue https://github.com/facebook/react-native/issues/18930) — committed to react-native-tvos/react-native-tvos by douglowder 5 years ago
- First set of changes for tvOS RN 0.61.2 (#23) * Add back TabBarIOS to 0.60.4 * Fixups to get RNTesterPods working on tvOS in 0.60.4 * Remove TabBarIOS deprecation warnings * YellowBox uses T... — committed to react-native-tvos/react-native-tvos by douglowder 5 years ago
Going forward, Apple TV is going to be supported in a community repo separate from RN core… https://github.com/react-native-community/react-native-tvos . Just added a commit that fixes this issue by adding a new
TVMenuControlmodule, with methods to enable and disable the menu key gesture handler. The commit includes changes to theRNTesterapp to show how to use the new module to enable the menu key when pushing a screen, and disabling the menu key when you’re back to the bottom level of your navigation.Sure.
I made a method that will look for the GestureHandler. Keep a reference to it in the AppDegelate. Later you can remove the GestureHandler when your app reaches the Top level. In this case the App will close and go to the Home screen. You can re-add the GestureRecognizer when necessary.
In case it helps anybody else, this was my workaround.
I added the below method to my bridge that lets me enable/disable the menu button gesture recognizer. If the gesture recognizer is enabled, we can handle the menu button and go back a screen. If the gesture recognizer is NOT enabled, the app will close.
Then in my javascript I call
NativeModules.YourBridge.setMenuHandlerEnabled(false);when my home screen mounts or the user returns to my homescreen. I callNativeModules.YourBridge.setMenuHandlerEnabled(true);when the user visits any other screen.I thought the Menu button would go back to the previous screen, and when the root screen of the app is reached, it would exit to the Apple TV home screen? The home button will always exit the app?
From the Apple Docs:
" Users expect to press the Menu button on the remote and return to a previous screen or the main Apple TV Home screen. Pressing Menu at the top level of an app or game should always exit to the Apple TV Home screen. During gameplay, pressing Menu should show or hide an in-game pause menu that includes an option to navigate back to the game’s main menu. "