1.

How can you write different code for IOS and Android in the same code base ? Is there any module available for this ?

Answer»

The platform MODULE detects the platform in which the app is running.

import { Platform, Stylesheet } from 'react-native';const styles = Stylesheet.create({height: Platform.OS === 'IOS' ? 200 : 400})

Additionally Platform.select method available that takes an object containing Platform.OS as KEYS and RETURNS the value for the platform you are currently on.

import { Platform, StyleSheet } from 'react-native';const styles = StyleSheet.create({ container: {FLEX: 1, ...Platform.select({ ios: { backgroundColor: 'red', }, android: { backgroundColor: 'green', }, default: { // other platforms, web for example backgroundColor: 'blue', }, }),},});


Discussion

No Comment Found