lucasferreira / react-native-send-intent

React Native Android module to use Android's Intent actions for send text to shareable apps or make phone calls or opening third party apps
419 stars 159 forks source link

Make it safe to require this module from iOS #19

Closed frantic closed 8 years ago

frantic commented 8 years ago

When requiring this module from iOS codebase (that doesn't have SendIntentAndroid) "Undefined is not an object" is thrown.

var RNSendIntentAndroid = require('react-native').NativeModules.SendIntentAndroid;

var SendIntentAndroid = {
    TEXT_PLAIN: RNSendIntentAndroid.TEXT_PLAIN,  // <-- RNSendIntentAndroid is undefined
    TEXT_HTML: RNSendIntentAndroid.TEXT_HTML,
    ...
}

Please consider making it safe to require from both platforms, so that the end used doesn't have to add if (Platform.OS === 'android') { require('react-native-send-intent'); } (which will stop working if RN transitions to ES6 modules).

lucasferreira commented 8 years ago

Hi @frantic

Thanks for the warning, I've changed the code of react-native-send-intent module to:

var SendIntentAndroid = {
    TEXT_PLAIN: (Platform.OS === 'android') ? RNSendIntentAndroid.TEXT_PLAIN : 'text/plain',
    TEXT_HTML: (Platform.OS === 'android') ? RNSendIntentAndroid.TEXT_HTML : 'text/html',
.....
}

Can you update the module install and test it again?