ReactNative: Android與iOS平臺兼容處理

方法一:

創建不同的文件擴展名:
*.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);
} 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章