10

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'; 
Almog
  • 2,639
  • 6
  • 30
  • 59
  • Yes, you can branch your codes into different OS, try to add this line in `App.android.js` (or similar JS OS-specific files). – Raptor Oct 09 '17 at 03:38
  • That doesn't really help the entire file is a component which is load into my main stack, I tried to rename it to .android but it still loads the files which in turn loads that import package which crashes my app – Almog Oct 09 '17 at 03:43

2 Answers2

6

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');
}
Community
  • 1
  • 1
Mahdi Bashirpour
  • 17,147
  • 12
  • 117
  • 144
  • If you use the second you might face issues where platform specific functions are no longer available, use the first way – DayzZombie Sep 21 '22 at 11:52
0

This Works:

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

takluiper
  • 679
  • 2
  • 8
  • 24
  • Where will you define this in a functional component? Inside functional component or outside of it ? – Roshan S Apr 16 '22 at 05:50