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.
Note
Android-specific filesIf we need to create a file that is supposed to only run on Android devices, simply name it <FILENAME>.android.js, just like the two index files. React Native will know exactly which file to build with, and this lets us create components that are platform-specific when...