React Native OOT platform API #1009
Replies: 2 comments 5 replies
|
+1 |
|
I like the idea of separating the concepts of operating system and device category through Platform.OS and Platform.Variant. The proposed API seems easier to reason about than maintaining long lists of platform-specific checks, especially as React Native expands to TVs, desktop environments, and headsets. One concern I have is the potential for confusion between Platform.OS and Platform.Variant when developers decide which one to use. For example, some libraries may check for Android while others may check for mobile, even when they are trying to solve the same problem. It could be helpful to provide clear guidelines and examples describing when platform-specific behavior should rely on Platform.OS versus Platform.Variant. This may help keep ecosystem APIs more consistent as additional out-of-tree platforms are added. ;) |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Adding notes and ideas here on defining the React Native core API for out-of-tree platform support. I'd really appreciate comments and feedback, to help firm these ideas up into something that could be submitted as an RFC.
(See “Formalize OOT platform concept (Vega, Desktop, TV, etc.)” in the list of projects in-flight in the React Foundation planning document. )
Updated 25 July 2026
Requirements
Changes to Platform.OS values
Platform.OS:iosandroidmacoswindowswebnativenative(it isn’t really a platform in the same sense as the others, just a way for Metro to identify non-web components)tvosandroidtvvegavisionos(?)metaquest(?)webtv(?)Carefully separate the concepts of Metroplatformand nativePlatform.OSPlatformnative implementationplatformflag that goes to the packager)platformflag used to build the embedded JS bundle)Platform.Variant
Platform.VariantAPI (similar toPlatform.OS) that returns whether we are on TV, desktop, etc.Platform.uiModeconstant.mobile(default)desktoptvheadsetwebPlatform.Variantwould be determined at runtime, the wayuiModeis determined for Android todayPlatform.Variant, have a namespace where all OOT platform specific APIs and components liveTVnamespace whereTVFocusGuideView,TVEventHandler, etc. would now liveDesktopnamespacereact-native-macosandreact-native-windowswould provide exactly identical APIs in theDesktopnamespacereact-native-tvosand Vega would do the same forTVMetro considerations
Platform.OSandPlatform.Variantmacosplatform, Metro would resolve these in order:Component.macos.tsxComponent.desktop.tsxComponent.tsxandroidtvplatform, Metro would also pick upandroidfor backward compatibilityComponent.androidtv.tsxComponent.android.tsxComponent.tv.tsxComponent.tsxAll reactions