React Native show share actions for Android and iOS.
This module uses ActionSheetIOS for iOS and a native bridge for Android.
npm install react-native-share-actions
react-native link
In your android/app/build.gradle
add:
dependencies {
compile project(':react-native-share-actions')
}
In your android/settings.gradle
add:
include ':react-native-share-actions'
project(':react-native-share-actions').projectDir = file('../node_modules/react-native-share-actions/android')
In your MainApplication.java
add:
import io.moori.rnshareactions.RNShareActionsPackage;
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new RNShareActionsPackage() // Add the package here
);
}
import ShareActions from 'react-native-share-actions';
async function handlePressShare() {
try {
const result = await ShareActions.share({
url: 'http://www.example.com',
message: 'This is a message',
subject: 'Example'
}, 'Share URL');
if (result.success) {
console.log(`Shared via ${result.method}`);
}
} catch (error) {
console.error(error);
}
}
var ShareActions = require('react-native-share-actions');
function handlePressShare() {
ShareActions.share({
url: 'http://www.example.com',
message: 'This is a message',
subject: 'Example'
}, 'Share URL')
.then(function(result) {
if (result.success) {
console.log(`Shared via ${result.method}`);
}
})
.catch(function(error) {
console.error(error);
});
}