Almog
Almog

Reputation: 2837

React Native import package only on Android

I'm trying to import a package only on Android here is the package anyone has any idea if this is possible?

import {ProcessingManager} from 'react-native-video-processing'; 

Upvotes: 11

Views: 5027

Answers (2)

takluiper
takluiper

Reputation: 689

This Works:

var DocPicker = (Platform.OS === 'android') ? require('react-native-file-picker') : require('react-native-document-picker');

Upvotes: 0

Mahdi Bashirpour
Mahdi Bashirpour

Reputation: 18803

You have two way for this:

First way:

You can separate platform code by creating two different files your_file_name.android.js and your_file_name.ios.js.

For example, you have to have this files in your directory

BigButton.ios.js
BigButton.android.js

You can then require the component as follows:

import BigButton from './BigButton'

reference: react netive

Second way:

I am not sure for this way

var ProcessingManager;

if (Platform.OS == 'android') {
    ProcessingManager = require('react-native-video-processing');
}

Upvotes: 6

Related Questions