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

前端 未结 3 1056
北海茫月
北海茫月 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:14

    platform-specific code is more complex, you should consider splitting the code out into separate files. React Native will detect when a file has a .ios. or .android. extension and load the relevant platform file when required from other components.

    For example, say you have the following files in your project:

    BigButton.ios.js
    BigButton.android.js
    

    You can then require the component as follows:

    import BigButton from './BigButton'
    

    reference https://facebook.github.io/react-native/docs/platform-specific-code.html#platform-specific-extensions

提交回复
热议问题