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

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

    To get around this I have been using require instead (but mainly for modules rather than components):

    var SafariView;
    
    if (Platform.OS == 'ios') {
        SafariView = require('react-native-safari-view');
    }
    

    For this particular situation I would definitely go for Konstantin Kuznetsov's approach - Just sticking this here as it might help someone else where making a wrapper component with separate files may be overkill :)

提交回复
热议问题