Skip to content
Android Share functionality for react-native
Branch: master
Clone or download
Latest commit fd8b891 Aug 16, 2016
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src/main Support RN 0.30 Jul 21, 2016
.gitignore Add image sharing Jul 5, 2016
README.md Add image sharing Jul 5, 2016
build.gradle removing version number Aug 8, 2016
example.png adding example file Feb 7, 2016
index.js fixing how we load the library using native modules Apr 8, 2016
package.json upgrading version number Aug 16, 2016

README.md

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

You can’t perform that action at this time.