React Native repo with additions for Apple TV and Android TV support.
React Native repo with additions for Apple TV and Android TV support.
Apple TV and Android TV support for React Native are maintained here and in the corresponding react-native-tvos npm package, and not in the core repo. This is a full fork of the main repository, with only the changes needed to support Apple TV and Android TV.
Releases of react-native-tvos will be based on a public release of react-native; e.g. the 0.81.0-0 release of this package will be derived from the 0.81.0 release of react-native. All releases of this repo will follow the 0.xx.x-y format, where x digits are from a specific RN core release, and y represents the additional versioning from this repo.
Releases will be published on npmjs.org and you may find the latest release version here: https://www.npmjs.com/package/react-native-tvos?activeTab=versions or use the tag @latest
You will find the relevant tvOS support and maintenance within the branches marked tvos-v0.xx.x;
To build your project for Apple TV, you should change your package.json imports to import react-native as follows, so that this package is used instead of the core react-native package.
"react-native": "npm:react-native-tvos@latest",You cannot use this package and the core react-native package simultaneously in a project.
This README covers only TV-specific features. For more general documentation and for changes between versions, you should also see these resources:
React Native TV fully implements the new architecture, identically to the core repo. You can read more about it in this blog post from the RN core team: The New Architecture Is Here
If, for any reason, the New Architecture is not behaving properly in your application, there is always the option to opt-out from it until you are ready to turn it on again.
To opt-out from the New Architecture:
Expo apps: See Expo's documentation.
Apple TV: You can reinstall the dependencies by running the command:
RCT_NEW_ARCH_ENABLED=0 bundle exec pod install-newArchEnabled=true
+newArchEnabled=falseTypescript types for TV-specific components and APIs have been added to types/public. This repo is also generating types for the new API currently in development by the core team.
Starting with the 0.81.0-0 release, this repo provides a precompiled framework for the React Native core library for iOS and tvOS. This framework is built using the Swift Package Manager and is available for both debug and release builds. The framework is available for both iOS and tvOS, and is provided as a Maven artifact in the io.github.react-native-tvos group, similarly to the Android artifacts from this repo.
Builds using the above framework also require the precompiled ReactNativeDependencies framework, and the Hermes engine framework. Both of these are built automatically for both iOS and tvOS and are included in the React Native core releases, and are not separately distributed.
TV device support has been implemented with the intention of making existing React Native applications "just work" on TV, with few or no changes needed in the JavaScript code for the applications.
The RNTester app supports iOS, Apple TV, Android, and Android TV. In this repo, RNTester/Podfile and RNTester/RNTesterPods.xcodeproj have been modified to work for tvOS.
Minimum operating system versions:
Podfile only have one target. This repo supports either an iOS target or a tvOS target.npm. We are following the same model, except that the Maven artifacts will be in group io.github.react-native-tvos instead of com.facebook.react. The @react-native/gradle-plugin module has been upgraded so that the Android dependencies will be detected correctly during build.Warning: Make sure you do not globally install
react-nativeorreact-native-tvos. If you have done this the wrong way, you may get error messages likeld: library not found for -lPods-TestApp-tvOS.
We strongly recommend Yarn as the package manager.
As of React Native version 0.75.x, the core team recommends Expo for new projects.
See the Building Expo apps for TV guide from Expo for details on how to set up a new Expo project, including supported Expo modules and limitations.
Using Expo's continuous native generation (CNG) model, projects created this way can be used to build either mobile or TV apps, taking advantage of the full support for both mobile and TV platforms in this repo.
We maintain template-tv, a TV-specific template for developers using the React Native Community CLI. This project extends the Community CLI with run-tvos, build-tvos, and log-tvos commands for tvOS development.
[!NOTE] This template only supports Apple TV and Android TV. Multiple platform targets are no longer supported in React Native app Podfiles.
Quick start:
# Initialize a new app called 'TVTest'
# This command should be run outside of any existing node project
npx @react-native-community/cli@latest init TVTest --template @react-native-tvos/template-tv
cd TVTest
# Build and run on tvOS Simulator (macOS only, requires Apple TV simulator)
npx react-native run-tvos --simulator "Apple TV"
# Build and run on Android TV emulator (requires Android TV emulator)
npx react-native run-android --device tv_api_31The template contains an example Metro configuration that allows Metro to resolve application source files with TV-specific code, indicated by specific file extensions (e.g. *.ios.tv.tsx, *.android.tv.tsx, *.tv.tsx). The config will work the same way with the other standard source file extensions (.js, etc.), as documented in Metro docs
When this is enabled, Metro will resolve files in the following order of preference (and similarly for the other supported file extensions):
file.ios.tv.tsx or file.android.tv.tsxfile.tv.tsxfile.ios.tsx or file.android.tsxfile.tsxThis config is not enabled by default, since it will impact bundling performance, but is available for developers who need this capability.
Platform React Native API.var Platform = require('Platform');
var running_on_tv = Platform.isTV;
// If you want to be more specific and only detect devices running tvOS
// (but no Android TV devices) you can use:
var running_on_apple_tv = Platform.isTVOS;Common codebase for iOS and tvOS: Since tvOS and iOS share most Objective-C and JavaScript code in common, most documentation for iOS applies equally to tvOS. Apple TV specific changes in native code are all wrapped by the TARGET_OS_TV define. These include changes to suppress APIs that are not supported on tvOS (e.g. web views, sliders, switches, status bar, etc.), and changes to support user input from the TV remote or keyboard.
Common codebase for Android phone and Android TV: Apps built for Android using this repo will run on both Android phone and Android TV. Most of the changes for TV are specific to handling focus-based navigation on a TV using the D-Pad on the remote control.
Pressable and Touchable controls: TV controls are supported with fully native events.
Code has been 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, so Pressable, TouchableHighlight and TouchableOpacity will "just work" on both Apple TV and Android TV. 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 (center button on Apple TV remote, or center button on Android TV DPad).onPressIn() will be executed when the TV remote "select" button is pressed down (center button on Apple TV remote, or center button on Android TV DPad)onPressOut() will be executed when the TV remote "select" button is releasedonLongPress() will be executed if the "select" button is held down for a length of time (this event is generated in the Pressability module, the same as for touchscreen long press events).TouchableNativeFeedback and TouchableWithoutFeedback respond to press events, but do not respond to focus and blur events, and are not recommended for TV.
Because focus and blur events are now fully native core events, they will respond correctly to capturing and bubbling event handlers in View components. A demo of this has been added to the TVEventHandlerExample in RNTester.
Tailwind styles for Pressable and Touchable controls: The above events allow RNTV to support the focus: and active: pseudo classes for Tailwind styles.
TV remote/keyboard input: Application code that needs to implement custom handling of TV remote events can create an instance of TVEventHandler and listen for these events. For a more convenient API, we provide useTVEventHandler.
…LogBox: The LogBox error/warning display (which replaced YellowBox in 0.63) is working as expected on TV platforms, after a few adjustments to make the controls accessible to the focus engine.
Dev Menu support:
_TV re
No open issues yet, or sync has not completed.