Can I require a module specifically for iOS in React Native?

前端 未结 3 1057
北海茫月
北海茫月 2021-02-07 13:31

I am currently using react-native-safari-view module in my React Native project for showing web views in iOS.

As the module is not yet implemented for Android, when I tr

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-07 14:19

    You can separate platform code by creating two different files your_file_name.android.js and your_file_name.ios.js. So you can create two versions for the file where you want to use SafariView or you can create a wrapper around SafariView which will export this module on iOS and dummy object on Android, and then use this wrapper with Platform.OS checks.

提交回复
热议问题