Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install package only for iOs or Android in React Native

I would like to know if it's possible to install a package only for iOs or Android in React Native ? I'm using tipsi-stripe for Apple Pay and there is some bugs with Android and RN0.61.5, and I don't need it on Android.

I tried to delete module from Android Studio and from packages.json and it's working but it's not clean, does someone have a better solution ?

like image 305
Joris Avatar asked Dec 23 '22 20:12

Joris


2 Answers

Try to add this in your react-native.config

module.exports = {
  ...
  dependencies: {
    'tipsi-stripe': {
      platforms: {
        android: null,
      },
    },
  },
};

like image 61
Tuan Luong Avatar answered Feb 05 '23 17:02

Tuan Luong


You can't install package only for IOS but you can import it based on platform as follow:

import { Platform } from 'react-native'

let ModuleName

if (Platform.OS === 'ios') {
  ModuleName = require('moduleName')
}
like image 37
obiwankenoobi Avatar answered Feb 05 '23 18:02

obiwankenoobi