O'Reilly logo

React Native By Example by Richard Kho

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Platform

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.

Android-specific files If we need to create a file that is supposed to only ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required