Find the OS type and version

suggest change

The first step is to import Platform from the ‘react-native’ package like so:

import { Platform } from 'react-native'

You can then read the OS with Platform.OS and use it in conditions. StyleSheet.create expects objects of style properties, not a bare number:

const styles = StyleSheet.create({
  box: {
    height: Platform.OS === 'ios' ? 200 : 100,
  },
})

If you want to detect the Android version, you can use Platform.Version like so:

if (Platform.Version === 21) {
  console.log('Running on Lollipop!');
}

On iOS, Platform.Version is a string. Parse it before a numeric comparison. On Android it is already a number.

if (parseInt(Platform.Version, 10) >= 9) {
    console.log('Running version higher than 8');
}

If the platform-specific logic is complex, you can split it into two files, for example:

and require it using

const MyTask = require('./MyTask')

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents