Skip to content

haydenth/react-native-android-share

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

[email protected] with questions or pull requests

About

Android Share functionality for react-native

Resources

Stars

Watchers

Forks

Packages

No packages published