创建不同的文件扩展名:
*.android.js
*.io.js
import { Platform } from ‘react-native‘;
if (Platform.OS === ‘android‘) {
// Do something specific for Android
} else if (Platform.OS === ‘ios‘) {
// Handle iOS
}
marginTop: Platform.OS === ‘ios‘ 10 : 0,
paddingBottom: Platform.OS === ‘android‘ 8 : 0
const myStyle = Platform.select({ios:{},android:{})
const myFn = Platform.select({ios:()=>{},android:()=>{})
myFn();
if (UIManager.setLayoutAnimationEnabledExperimental) {
UIManager.setLayoutAnimationEnabledExperimental(true);
}
ReactNative: Android与iOS平台兼容处理
原文:https://blog.51cto.com/14565733/2454644