April 2017
Intermediate to advanced
414 pages
8h 14m
English
When your files have such little variance in the differences between their iOS and Android functionalities, it's okay to use the same file. Utilizing the Platform API, we can identify the type of mobile device the user is on and conditionally send them down a specific path.
Import the Platform API along with the rest of your React Native components:
import { Platform } from 'react-native';
Then call its OS property within a component:
_platformConditional () { if (Platform.OS === 'ios') { doSomething(); } if (Platform.OS === 'android') { doSomethingElse(); } }
This lets us control the path our app takes and allows for a little bit of code reuse.
Read now
Unlock full access