Skip to main content
Version: 0.67

Platform

Example​


Reference

Properties​

constants​

Platform.constants;

Returns an object which contains all available common and specific constants related to the platform.

Properties:

Name
TypeOptionalDescription
isTestingbooleanNo
reactNativeVersionobjectNoInformation about React Native version. Keys are major, minor, patch with optional prerelease and values are numbers.
Version
Android
numberNoOS version constant specific to Android.
Release
Android
stringNo
Serial
Android
stringNoHardware serial number of an Android device.
Fingerprint
Android
stringNoA string that uniquely identifies the build.
Model
Android
stringNoThe end-user-visible name for the Android device.
Brand
Android
stringNoThe consumer-visible brand with which the product/hardware will be associated.
Manufacturer
Android
stringNoThe manufacturer of the Android device.
ServerHost
Android
stringYes
uiMode
Android
stringNoPossible values are: 'car', 'desk', 'normal','tv', 'watch' and 'unknown'. Read more about Android ModeType.
forceTouchAvailable
iOS
booleanNoIndicate the availability of 3D Touch on a device.
interfaceIdiom
iOS
stringNoThe interface type for the device. Read more about UIUserInterfaceIdiom.
osVersion
iOS
stringNoOS version constant specific to iOS.
systemName
iOS
stringNoOS name constant specific to iOS.

isPad
iOS
​

Platform.isPad;

Returns a boolean which defines if device is an iPad.

Type
boolean

isTV​

Platform.isTV;

Returns a boolean which defines if device is a TV.

Type
boolean

isTesting​

Platform.isTesting;

Returns a boolean which defines if application is running in Developer Mode with testing flag set.

Type
boolean

OS​

static Platform.OS

Returns string value representing the current OS.

Type
enum('android', 'ios')

Version​

Platform.Version;

Returns the version of the OS.

Type
number
Android

string
iOS

Methods​

select()​

static select(config: object): any

Returns the most fitting value for the platform you are currently running on.

Parameters:​

NameTypeRequiredDescription
configobjectYesSee config description below.

Select method returns the most fitting value for the platform you are currently running on. That is, if you're running on a phone, android and ios keys will take preference. If those are not specified, native key will be used and then the default key.

The config parameter is an object with the following keys:

  • android (any)
  • ios (any)
  • native (any)
  • default (any)

Example usage:

import {Platform, StyleSheet} from 'react-native';

const styles = StyleSheet.create({
container: {
flex: 1,
...Platform.select({
android: {
backgroundColor: 'green',
},
ios: {
backgroundColor: 'red',
},
default: {
// other platforms, web for example
backgroundColor: 'blue',
},
}),
},
});

This will result in a container having flex: 1 on all platforms, a green background color on Android, a red background color on iOS, 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:

const Component = Platform.select({
ios: () => require('ComponentIOS'),
android: () => require('ComponentAndroid'),
})();

<Component />;
const Component = Platform.select({
native: () => require('ComponentForNative'),
default: () => require('ComponentForWeb'),
})();

<Component />;