方法一:react
建立不一樣的文件擴展名:android
*.android.js *.io.js
方法二:ios
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
方法三:react-native
const myStyle = Platform.select({ios:{},android:{}) const myFn = Platform.select({ios:()=>{},android:()=>{}) myFn();
方法四:code
if (UIManager.setLayoutAnimationEnabledExperimental) { UIManager.setLayoutAnimationEnabledExperimental(true); }