This fires off the default android share tray:
npm i react-native-android-share --save
- In
android/setting.gradle
...
include ':RNAndroidShare', ':app'
project(':RNAndroidShare').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-android-share')
- In
android/app/build.gradle
...
dependencies {
...
compile project(':RNAndroidShare')
}
- Register Module in your MainActivity.java
import com.blueprintalpha.rnandroidshare.RNAndroidSharePackage; // <--- import
public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
......
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new RNAndroidSharePackage(this) // <------ add this line to your MainActivity class
);
}
......
}
- Now implement into your code
var React = require('react-native')
var {
View,
Text,
TouchableHighlight,
Image,
} = React
var AndroidShare = require('react-native-android-share');
var ShareButton = React.createClass({
// this will open the share tray
_showShareActionSheet(story) {
var object = {subject: 'Story Title', text: 'Message Body'};
AndroidShare.openChooserWithOptions(object, 'Share Story');
},
// render a simple button
render() {
return (
<TouchableHighlight
underlayColor='rgba(0,0,0,0)'
resizeMode='cover'
onPress={()=>this._showShareActionSheet(this.props.story)}>
<Image source={require("../images/share.png")}
width={45}
height={45}
style={{height:45, width:45}}/>
</TouchableHighlight>);
},
});
module.exports = ShareButton;
- right now, module basically returns an empty view. need to either make this a component OR just a file with classes in it.
[email protected] with questions or pull requests