react-native-android-share

0.0.5 • Public • Published

react-native-android-share

This fires off the default android share tray:

Installl

npm i react-native-android-share --save

Add it to your android project

  • 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;
 

TODO

  • right now, module basically returns an empty view. need to either make this a component OR just a file with classes in it.

CONTACT

thayden@gmail.com with questions or pull requests

Package Sidebar

Install

npm i react-native-android-share

Weekly Downloads

0

Version

0.0.5

License

MIT

Last publish

Collaborators

  • haydenth