Share Social , Sending Simple Data to Other Apps
npm i --save react-native-share
- In
android/setting.gradle
...
include ':react-native-share', ':app'
project(':react-native-share').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-share/android')
- In
android/app/build.gradle
...
dependencies {
...
compile project(':react-native-share')
}
- register module (in MainActivity.java)
import cl.json.RNSharePackage; // <--- import
public class MainActivity extends ReactActivity {
......
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new RNSharePackage() // <------ add here
);
}
......
}
- Add it to your iOS project
Run npm install react-native-share --save
Open your project in XCode, right click on Libraries and click Add Files to "Your Project Name".
Add libRNShare.a to Build Phases -> Link Binary With Libraries.
var React = require('react-native');
var Share = require('react-native-share');
var TouchableHighlight = require('TouchableHighlight');
var example = React.createClass({
onShare: function() {
Share.open({
share_text: "Hola mundo",
share_URL: "http://google.cl",
title: "Share Link"
},function(e) {
console.log(e);
});
/*
// in iOS without callback
Share.open({
share_text: "Hola mundo",
share_URL: "http://google.cl",
title: "Share Link"
});
*/
},
render: function() {
return (
<View style={styles.container}>
<TouchableHighlight onPress={this.onShare}>
<Text style={styles.instructions}>
Share
</Text>
</TouchableHighlight>
</View>
);
}
});
var styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
AppRegistry.registerComponent('example', () => example);