Building For TV Devices React Native
Building For TV Devices React Native
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
<!-- Add custom banner image to display as Android TV launcher icon -->
<application
...
android:banner="@drawable/tv_banner"
>
...
<intent-filter>
...
<!-- Needed to properly create a launch intent when running on Android TV -->
<category android:name="android.intent.category.LEANBACK_LAUNCHER"/>
</intent-filter>
...
</application>
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
https://reactnative.dev/docs/building-for-tv 1/3
28/2/24, 11:34 Building For TV Devices · React Native
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, so
TouchableWithoutFeedback , TouchableHighlight , TouchableOpacity and
TouchableNativeFeedback will work as expected. In particular:
onFocus will be executed when the touchable view goes into focus
onBlur will be executed when the touchable view goes out of focus
_enableTVEventHandler() {
this._tvEventHandler = new TVEventHandler();
this._tvEventHandler.enable(this, function (cmp, evt) {
if (evt && evt.eventType === 'right') {
cmp.setState({board: cmp.state.board.move(2)});
} else if (evt && evt.eventType === 'up') {
cmp.setState({board: cmp.state.board.move(1)});
} else if (evt && evt.eventType === 'left') {
cmp.setState({board: cmp.state.board.move(0)});
} else if (evt && evt.eventType === 'down') {
cmp.setState({board: cmp.state.board.move(3)});
} else if (evt && evt.eventType === 'playPause') {
cmp.restartGame();
}
});
}
_disableTVEventHandler() {
if (this._tvEventHandler) {
this._tvEventHandler.disable();
delete this._tvEventHandler;
}
https://reactnative.dev/docs/building-for-tv 2/3
28/2/24, 11:34 Building For TV Devices · React Native
componentDidMount() {
this._enableTVEventHandler();
}
componentWillUnmount() {
this._disableTVEventHandler();
}
}
Dev Menu support: On the emulator, cmd-M will bring up the Dev 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() .
https://reactnative.dev/docs/building-for-tv 3/3