Using Platform in react-native

Sometimes you need to change the UI of your application according to the mobile OS.

Using Platform can help you do what you want.

1) The first step is importing platform:

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

2) Then go to the render(){} method and do some stuff as bellow:

All you need in this section is checking the OS of the device.

render() {
if (Platform.OS === 'ios') {
return (
...
);
} else {
return (
...
);
}
}

3) In the end, set your components:

render() {
if (Platform.OS === 'ios') {
return (
<Text>IOS</Text>
);
} else {
return (
<Text>Android</Text>
);
}
}

Sahand Mahdavi

سهند مهدوی

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store