├── .gitignore ├── README.md ├── build.gradle ├── example.png ├── index.js ├── package.json └── src └── main ├── AndroidManifest.xml └── java └── com └── blueprintalpha └── rnandroidshare ├── RNAndroidShare.java └── RNAndroidSharePackage.java /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-native-android-share 2 | 3 | This fires off the default android share tray: 4 | 5 | 6 | 7 | ### Installl 8 | 9 | ``` 10 | npm i react-native-android-share --save 11 | ``` 12 | 13 | ### Add it to your android project 14 | 15 | * In `android/setting.gradle` 16 | 17 | ```gradle 18 | ... 19 | include ':RNAndroidShare', ':app' 20 | project(':RNAndroidShare').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-android-share') 21 | ``` 22 | 23 | * In `android/app/build.gradle` 24 | 25 | ```gradle 26 | ... 27 | dependencies { 28 | ... 29 | compile project(':RNAndroidShare') 30 | } 31 | ``` 32 | 33 | * Register Module in your MainActivity.java 34 | 35 | ```java 36 | import com.blueprintalpha.rnandroidshare.RNAndroidSharePackage; // <--- import 37 | 38 | public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler { 39 | ...... 40 | 41 | @Override 42 | protected List getPackages() { 43 | return Arrays.asList( 44 | new MainReactPackage(), 45 | new RNAndroidSharePackage(this) // <------ add this line to your MainActivity class 46 | ); 47 | } 48 | 49 | ...... 50 | 51 | } 52 | ``` 53 | 54 | * Now implement into your code 55 | 56 | ```js 57 | var React = require('react-native') 58 | var { 59 | View, 60 | Text, 61 | TouchableHighlight, 62 | Image, 63 | } = React 64 | var AndroidShare = require('react-native-android-share'); 65 | 66 | var ShareButton = React.createClass({ 67 | 68 | // this will open the share tray 69 | _showShareActionSheet(story) { 70 | var object = {subject: 'Story Title', text: 'Message Body'}; 71 | AndroidShare.openChooserWithOptions(object, 'Share Story'); 72 | }, 73 | 74 | // render a simple button 75 | render() { 76 | return ( 77 | this._showShareActionSheet(this.props.story)}> 81 | 85 | ); 86 | }, 87 | }); 88 | 89 | module.exports = ShareButton; 90 | 91 | ``` 92 | 93 | TODO 94 | ===================== 95 | * right now, module basically returns an empty view. need to either make this a component OR just a file with classes in it. 96 | 97 | CONTACT 98 | ==================== 99 | thayden@gmail.com with questions or pull requests 100 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | mavenCentral() 4 | } 5 | dependencies { 6 | classpath 'com.android.tools.build:gradle:1.3.1' 7 | } 8 | } 9 | 10 | apply plugin: 'com.android.library' 11 | 12 | android { 13 | compileSdkVersion 23 14 | buildToolsVersion "23.0.3" 15 | 16 | defaultConfig { 17 | minSdkVersion 16 18 | targetSdkVersion 23 19 | versionCode 5 20 | versionName "1.5" 21 | } 22 | } 23 | 24 | dependencies { 25 | compile 'com.facebook.react:react-native:+' 26 | } 27 | -------------------------------------------------------------------------------- /example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haydenth/react-native-android-share/fd8b891fb858a25d1159c7daad39647083aa808f/example.png -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var invariant = require('invariant'); 4 | var React = require('react-native'); 5 | var { 6 | NativeModules: { 7 | RNAndroidShare 8 | } 9 | } = require('react-native'); 10 | 11 | var AndroidShare = { 12 | 13 | openChooserWithOptions(options: Object, title: string) { 14 | invariant( 15 | typeof options === 'object', 16 | 'A valid option object is required' 17 | ); 18 | invariant( 19 | typeof title === 'string', 20 | 'Invalid Title: should be a string. Was: ' + title 21 | ); 22 | console.log('calling android share chooser'); 23 | RNAndroidShare.openChooserWithOptions(options, title); 24 | }, 25 | 26 | render() { 27 | return (); 28 | } 29 | 30 | }; 31 | module.exports = AndroidShare; 32 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-android-share", 3 | "version": "0.0.5", 4 | "description": "Android tray to share things", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [ 10 | "react", 11 | "react-native", 12 | "react-component", 13 | "android" 14 | ], 15 | "author": "Tom Hayden ", 16 | "license": "MIT", 17 | "repository": { 18 | "type": "git", 19 | "url": "git+https://github.com/haydenth/react-native-android-share.git" 20 | }, 21 | "bugs": { 22 | "url": "https://github.com/haydenth/react-native-android-share/issues" 23 | }, 24 | "peerDependencies": { 25 | "react-native": ">=0.13" 26 | }, 27 | "homepage": "https://github.com/haydenth/react-native-android-share#readme", 28 | "dependencies": { 29 | "invariant": "^2.2.1" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/main/java/com/blueprintalpha/rnandroidshare/RNAndroidShare.java: -------------------------------------------------------------------------------- 1 | package com.blueprintalpha.rnandroidshare; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.net.Uri; 6 | 7 | import com.facebook.react.bridge.ReactApplicationContext; 8 | import com.facebook.react.bridge.ReactContextBaseJavaModule; 9 | import com.facebook.react.bridge.ReactMethod; 10 | import com.facebook.react.bridge.ReadableMap; 11 | 12 | class RNAndroidShare extends ReactContextBaseJavaModule { 13 | 14 | public RNAndroidShare(ReactApplicationContext reactContext) { 15 | super(reactContext); 16 | } 17 | 18 | @Override 19 | public String getName() { 20 | return "RNAndroidShare"; 21 | } 22 | 23 | @ReactMethod 24 | public void openChooserWithOptions(ReadableMap options, String title) { 25 | 26 | Intent intent = new Intent(Intent.ACTION_SEND); 27 | 28 | if (options.hasKey("subject")) { 29 | intent.putExtra(Intent.EXTRA_SUBJECT, options.getString("subject")); 30 | } 31 | 32 | if (options.hasKey("text")) { 33 | intent.putExtra(Intent.EXTRA_TEXT, options.getString("text")); 34 | } 35 | 36 | if (options.hasKey("imageUrl")) { 37 | Uri uri = Uri.parse(options.getString("imageUrl")); 38 | intent.putExtra(Intent.EXTRA_STREAM, uri); 39 | intent.setType("image/*"); 40 | } else { 41 | intent.setType("text/plain"); 42 | } 43 | 44 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 45 | 46 | Activity currentActivity = getCurrentActivity(); 47 | if (currentActivity != null) { 48 | currentActivity.startActivity(Intent.createChooser(intent, title)); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/blueprintalpha/rnandroidshare/RNAndroidSharePackage.java: -------------------------------------------------------------------------------- 1 | package com.blueprintalpha.rnandroidshare; 2 | 3 | import com.facebook.react.ReactPackage; 4 | import com.facebook.react.bridge.JavaScriptModule; 5 | import com.facebook.react.bridge.NativeModule; 6 | import com.facebook.react.bridge.ReactApplicationContext; 7 | import com.facebook.react.uimanager.ViewManager; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | public class RNAndroidSharePackage implements ReactPackage { 13 | 14 | @Override 15 | public List createNativeModules(ReactApplicationContext reactContext) { 16 | List modules = new ArrayList<>(); 17 | modules.add(new RNAndroidShare(reactContext)); 18 | return modules; 19 | } 20 | 21 | @Override 22 | public List> createJSModules() { 23 | return new ArrayList<>(); 24 | } 25 | 26 | @Override 27 | public List createViewManagers(ReactApplicationContext reactContext) { 28 | return new ArrayList<>(); 29 | } 30 | } 31 | --------------------------------------------------------------------------------