Skip to content

Share Social , Sending Simple Data to Other Apps

License

Notifications You must be signed in to change notification settings

Pod-Point/react-native-share

 
 

Repository files navigation

react-native-share

Share Social , Sending Simple Data to Other Apps

Installation

npm i --save react-native-share

Add to your Android project

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

Example

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

how it looks:

Demo

About

Share Social , Sending Simple Data to Other Apps

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 49.5%
  • Objective-C 36.3%
  • JavaScript 14.2%