Platform
Example
import React from 'react';
import {Platform, StyleSheet, Text, ScrollView} from 'react-native';
const App = () => {
return (
<ScrollView contentContainerStyle={styles.container}>
<Text>OS</Text>
<Text style={styles.value}>{Platform.OS}</Text>
<Text>OS Version</Text>
<Text style={styles.value}>{Platform.Version}</Text>
<Text>isTV</Text>
<Text style={styles.value}>{Platform.isTV.toString()}</Text>
{Platform.OS === 'kepler' && <>
<Text>keplerOSVariant</Text>
<Text style={styles.value}>{Platform.constants.keplerOSVariant}</Text>
</>}
<Text>Constants</Text>
<Text style={styles.value}>
{JSON.stringify(Platform.constants, null, 2)}
</Text>
</ScrollView>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
value: {
fontWeight: '600',
padding: 4,
marginBottom: 8,
},
});
export default App;
Reference
Properties
constants
static constants: PlatformConstants;
Returns an object which contains all available common and specific constants related to the platform.
Properties:
Name | Type | Optional | Description |
---|---|---|---|
isTesting | boolean | No | |
reactNativeVersion | object | No | Information about React Native version. Keys are major , minor , patch with optional prerelease and values are number s. |
isTV
static isTV: boolean;
Returns a boolean which defines if device is a TV.
Type |
---|
boolean |
isTesting
static isTesting: boolean;
Returns a boolean which defines if application is running in Developer Mode with testing flag set.
Type |
---|
boolean |
OS
static OS: 'kepler';
Returns string value representing the current OS.
Type |
---|
enum('kelper' ) |
Methods
select
static select(config: Record<string, T>): T;
Returns the most fitting value for the platform you are currently running on.
Parameters:
Name | Type | Required | Description |
---|---|---|---|
config | object | Yes | See config description below. |
Select method returns the most fitting value for the platform you are currently running on. If not specified, kepler
key then native
key will be used and then the default
key.
The config
parameter is an object with the following keys:
kepler
(any)native
(any)default
(any)
Example usage:
import {Platform, StyleSheet} from 'react-native';
const styles = StyleSheet.create({
container: {
flex: 1,
...Platform.select({
kepler: {
backgroundColor: 'yellow',
},
default: {
// other platforms, web for example
backgroundColor: 'blue',
},
}),
},
});
This will result in a container having flex: 1
on all platforms a yellow background on Kepler and a blue background color on other platforms.
Since the value of the corresponding platform key can be of type any
, select
method can also be used to return platform-specific components, like below:
Since the value of the corresponding platform key can be of type any
, select
method can also be used to return platform-specific components, like below:
const Component = Platform.select({
kepler: () => require('ComponentKepler'),
})();
<Component />;
const Component = Platform.select({
native: () => require('ComponentForNative'),
default: () => require('ComponentForWeb'),
})();
<Component />;
Last updated: Sep 30, 2025