Building For TV Devices
TV devices support has been implemented with the intention of making existing React Native applications work on Apple TV and Android TV, with few or no changes needed in the JavaScript code for the applications.
- Android TV
- 🚧 tvOS
Build changes
- Native layer: To run React Native project on Android TV make sure to make the following changes to
AndroidManifest.xml
- JavaScript layer: Support for Android TV has been added to
Platform.android.js
. You can check whether code is running on Android TV by doing
Code changes
Access to touchable controls: When running on Android TV the Android framework will automatically apply a directional navigation scheme based on relative position of focusable elements in your views. The
Touchable
mixin has code added to detect focus changes and use existing methods to style the components properly and initiate the proper actions when the view is selected using the TV remote, soTouchableWithoutFeedback
,TouchableHighlight
,TouchableOpacity
andTouchableNativeFeedback
will work as expected. In particular:onFocus
will be executed when the touchable view goes into focusonBlur
will be executed when the touchable view goes out of focusonPress
will be executed when the touchable view is actually selected by pressing the "select" button on the TV remote.
TV remote/keyboard input: A new native class,
ReactAndroidTVRootViewHelper
, sets up key events handlers for TV remote events. When TV remote events occur, this class fires a JS event. This event will be picked up by instances of theTVEventHandler
JavaScript object. Application code that needs to implement custom handling of TV remote events can create an instance ofTVEventHandler
and listen for these events, as in the following code:
Dev Menu support: On the simulator, cmd-M will bring up the developer menu, similar to Android. To bring it up on a real Android TV device, press the menu button or long press the fast-forward button on the remote. (Please do not shake the Android TV device, that will not work :) )
Known issues:
TextInput
components do not work for now (i.e. they cannot receive focus automatically, see this comment).- It is however possible to use a ref to manually trigger
inputRef.current.focus()
. - You can wrap your input inside a
TouchableWithoutFeedback
component and trigger focus in theonFocus
event of that touchable. This enables opening the keyboard via the arrow keys. - The keyboard might reset its state after each keypress (this might only happen inside the Android TV emulator).
- It is however possible to use a ref to manually trigger
- The content of
Modal
components cannot receive focus, see this issue for details.