├── .gitignore ├── .npmignore ├── LICENSE ├── README.md ├── RNGoogleAppInvites ├── RNGoogleAppInvites.h └── RNGoogleAppInvites.m ├── android ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── slowpath │ └── googleappinvites │ ├── RNGoogleAppInvitesModule.java │ └── RNGoogleAppInvitesPackage.java ├── index.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # Xcode 6 | # 7 | build/ 8 | *.pbxuser 9 | !default.pbxuser 10 | *.mode1v3 11 | !default.mode1v3 12 | *.mode2v3 13 | !default.mode2v3 14 | *.perspectivev3 15 | !default.perspectivev3 16 | xcuserdata 17 | *.xccheckout 18 | *.moved-aside 19 | DerivedData 20 | *.hmap 21 | *.ipa 22 | *.xcuserstate 23 | project.xcworkspace 24 | 25 | # node.js 26 | # 27 | node_modules/ 28 | npm-debug.log 29 | 30 | # Built application files 31 | *.apk 32 | *.ap_ 33 | 34 | # Files for the Dalvik VM 35 | *.dex 36 | 37 | # Java class files 38 | *.class 39 | 40 | # Generated files 41 | bin/ 42 | gen/ 43 | 44 | # Gradle files 45 | .gradle/ 46 | build/ 47 | 48 | # Local configuration file (sdk path, etc) 49 | local.properties 50 | 51 | # Proguard folder generated by Eclipse 52 | proguard/ 53 | 54 | # Log Files 55 | *.log 56 | 57 | # Android Studio Navigation editor temp files 58 | .navigation/ 59 | 60 | # Android Studio captures folder 61 | captures/ 62 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | img 2 | example 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Apptailor 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-native-google-app-invites 2 | Let your users sign in with their Google account and Invite your 3 | contacts to use the app. 4 | 5 | react-native-google-app-invites is a wrapper around Google App Invites so it can be used from an React Native application. 6 | 7 | ## Requirements 8 | 9 | - iOS 7+ 10 | - React Native >0.14 11 | - CocoaPods 12 | 13 | ## Installation 14 | 15 | ```bash 16 | npm install react-native-google-app-invites --save 17 | ``` 18 | 19 | ## iOS 20 | 21 | You will need: 22 | 23 | CocoaPods ([Setup](https://guides.cocoapods.org/using/getting-started.html#installation)) 24 | 25 | ### Google project configuration for iOS 26 | 27 | - Open https://developers.google.com/app-invites/ios/ 28 | - Follow the instalation steps for CocoaPods 29 | 30 | ## Android 31 | 32 | ### Google project configuration 33 | 34 | - Install `Google Repository` package in `Android SDK Manager`: 35 | 1) Run in terminal window `android` (will start Android SDK Manager) 36 | 2) Install in `Extras` folder package `Google Repository` 37 | 38 | - Open https://developers.google.com/app-invites/android/ 39 | - Follow the instalation steps 40 | 41 | * In `android/setting.gradle` 42 | 43 | ```gradle 44 | ... 45 | include ':react-native-google-app-invites', ':app' 46 | project(':react-native-google-app-invites').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-google-app-invites/android') 47 | ``` 48 | 49 | * In `android/build.gradle` 50 | 51 | ```gradle 52 | ... 53 | dependencies { 54 | classpath 'com.android.tools.build:gradle:1.3.1' 55 | classpath 'com.google.gms:google-services:1.5.0' // <--- add this 56 | } 57 | ``` 58 | 59 | * In `android/app/build.gradle` 60 | 61 | ```gradle 62 | apply plugin: "com.android.application" 63 | apply plugin: 'com.google.gms.google-services' // <--- add this at the TOP 64 | ... 65 | dependencies { 66 | compile fileTree(dir: "libs", include: ["*.jar"]) 67 | compile "com.android.support:appcompat-v7:23.0.1" 68 | compile "com.facebook.react:react-native:0.14.+" 69 | compile project(":react-native-google-app-invites") // <--- add this 70 | } 71 | ``` 72 | 73 | * Register Module (in MainActivity.java) 74 | 75 | ```java 76 | import com.slowpath.googleappinvites.RNGoogleAppInvitesModule; // <--- import 77 | import com.slowpath.googleappinvites.RNGoogleAppInvitesPackage; // <--- import 78 | 79 | public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler { 80 | ...... 81 | 82 | @Override 83 | protected void onCreate(Bundle savedInstanceState) { 84 | super.onCreate(savedInstanceState); 85 | mReactRootView = new ReactRootView(this); 86 | 87 | mReactInstanceManager = ReactInstanceManager.builder() 88 | .setApplication(getApplication()) 89 | .setBundleAssetName("index.android.bundle") 90 | .setJSMainModuleName("index.android") 91 | .addPackage(new MainReactPackage()) 92 | .addPackage(new RNGoogleAppInvitesPackage(this)) // <------ add this line to yout MainActivity class 93 | .setUseDeveloperSupport(BuildConfig.DEBUG) 94 | .setInitialLifecycleState(LifecycleState.RESUMED) 95 | .build(); 96 | 97 | mReactRootView.startReactApplication(mReactInstanceManager, "AndroidRNSample", null); 98 | 99 | setContentView(mReactRootView); 100 | } 101 | 102 | // add this method inside your activity class 103 | @Override 104 | protected void onActivityResult(int requestCode, int resultCode, android.content.Intent data) { 105 | if (requestCode == RNGoogleAppInvitesModule.RC_APP_INVITES_IN) { 106 | RNGoogleAppInvitesModule.onActivityResult(resultCode, data); 107 | } 108 | super.onActivityResult(requestCode, resultCode, data); 109 | } 110 | 111 | ...... 112 | 113 | } 114 | ``` 115 | 116 | 117 | # Usage 118 | 119 | From your JS files for both iOS and Android: 120 | 121 | ```js 122 | var { NativeAppEventEmitter, DeviceEventEmitter } = require('react-native'); 123 | var GoogleAppInvites = require('react-native-google-app-invites'); 124 | 125 | if (Platform.OS === "ios") { 126 | GoogleAppInvites.configure( 127 | CLIENT_ID, // from .plist file 128 | SCOPES // array of authorization names: eg ['https://www.googleapis.com/auth/plus.login'] 129 | ); 130 | } else { 131 | GoogleAppInvites.init() 132 | } 133 | 134 | let Emitter = (Platform.OS === "android") ? DeviceEventEmitter : NativeAppEventEmitter; 135 | 136 | Emitter.addListener('googleAppInvitesError', (error) => { 137 | console.log('ERROR App Invites in', error); 138 | }); 139 | 140 | Emitter.addListener('googleAppInviteIds', (body) => { 141 | console.log('User invited these IDS:', body); 142 | }); 143 | 144 | GoogleAppInvites.invite("Message", "Title", "http://deepLink"); 145 | ``` 146 | 147 | -------------------------------------------------------------------------------- /RNGoogleAppInvites/RNGoogleAppInvites.h: -------------------------------------------------------------------------------- 1 | #ifndef RN_GoogleAppInvites_h 2 | #define RN_GoogleAppInvites_h 3 | 4 | #import "RCTBridgeModule.h" 5 | #import 6 | #import 7 | 8 | @class GGLContext; 9 | 10 | @interface RNGoogleAppInvites : NSObject 11 | 12 | @property (strong, nonatomic) id inviteDialog; 13 | 14 | // Register AppInvites 15 | + (BOOL)applicationDidFinishLaunching; 16 | 17 | // Receive Invitation from outside URL 18 | - (BOOL)application:(UIApplication *)application 19 | openURL:(NSURL *)url 20 | sourceApplication:(NSString *)sourceApplication 21 | annotation:(id)annotation; 22 | 23 | @end 24 | 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /RNGoogleAppInvites/RNGoogleAppInvites.m: -------------------------------------------------------------------------------- 1 | #import "RNGoogleAppInvites.h" 2 | #import "RCTEventDispatcher.h" 3 | 4 | @implementation RNGoogleAppInvites 5 | 6 | static NSString* kTrackingID = @"YOUR_TRACKING_ID"; 7 | 8 | RCT_EXPORT_MODULE(); 9 | 10 | @synthesize bridge = _bridge; 11 | 12 | RCT_EXPORT_METHOD(invite:(NSString *) message 13 | withTitle:(NSString *) title 14 | withDeepLink:(NSString *) deepLink) 15 | { 16 | self.inviteDialog = [GINInvite inviteDialog]; 17 | [self.inviteDialog setInviteDelegate: self]; 18 | 19 | // A message hint for the dialog. Note this manifests differently depending on the 20 | // received invation type. For example, in an email invite this appears as the subject. 21 | [self.inviteDialog setMessage: message]; 22 | 23 | // Title for the dialog, this is what the user sees before sending the invites. 24 | [self.inviteDialog setTitle: title]; 25 | [self.inviteDialog setDeepLink: deepLink]; 26 | [self.inviteDialog open]; 27 | } 28 | 29 | RCT_EXPORT_METHOD(configure:(NSString *)clientID withScopes:(NSArray *)scopes) 30 | { 31 | [GIDSignIn sharedInstance].delegate = self; 32 | [GIDSignIn sharedInstance].uiDelegate = self; 33 | 34 | [GIDSignIn sharedInstance].clientID = clientID; 35 | [GIDSignIn sharedInstance].scopes = scopes; 36 | 37 | [GIDSignIn sharedInstance].allowsSignInWithBrowser = NO; 38 | } 39 | 40 | RCT_EXPORT_METHOD(signIn) 41 | { 42 | [[GIDSignIn sharedInstance] signIn]; 43 | } 44 | 45 | RCT_EXPORT_METHOD(signOut) 46 | { 47 | [[GIDSignIn sharedInstance] signOut]; 48 | } 49 | 50 | - (dispatch_queue_t)methodQueue 51 | { 52 | return dispatch_get_main_queue(); 53 | } 54 | 55 | + (BOOL)applicationDidFinishLaunching { 56 | NSError* configureError; 57 | [[GGLContext sharedInstance] configureWithError:&configureError]; 58 | NSAssert(!configureError, @"Error configuring Google services: %@", configureError); 59 | 60 | [GINInvite applicationDidFinishLaunching]; 61 | 62 | if ([kTrackingID compare:@"YOUR_TRACKING_ID"] != NSOrderedSame) { 63 | [GINInvite setGoogleAnalyticsTrackingId: kTrackingID]; 64 | } 65 | 66 | return YES; 67 | } 68 | 69 | // This is called whenever the user get's invite URL 70 | - (BOOL)application:(UIApplication *)application 71 | openURL:(NSURL *)url 72 | sourceApplication:(NSString *)sourceApplication 73 | annotation:(id)annotation { 74 | 75 | GINReceivedInvite *invite = [GINInvite handleURL:url 76 | sourceApplication:sourceApplication 77 | annotation:annotation]; 78 | if (invite) { 79 | [GINInvite completeInvitation]; 80 | 81 | NSString *matchType = 82 | (invite.matchType == kGINReceivedInviteMatchTypeWeak) ? @"Weak" : @"Strong"; 83 | NSDictionary *body = @{ 84 | @"matchType": matchType, 85 | @"deepLinkFrom": sourceApplication, 86 | @"inviteId": invite.inviteId, 87 | @"appURL": invite.deepLink, 88 | }; 89 | [self.bridge.eventDispatcher sendAppEventWithName:@"googleAppInviteConvertion" body:body]; 90 | 91 | [GINInvite convertInvitation:invite.inviteId]; 92 | 93 | return YES; 94 | } 95 | 96 | return [[GIDSignIn sharedInstance] handleURL:url 97 | sourceApplication:sourceApplication 98 | annotation:annotation]; 99 | } 100 | 101 | // This is called when the inviteTapped method is done 102 | - (void)inviteFinishedWithInvitations:(NSArray *)invitationIds 103 | error:(NSError *)error { 104 | NSDictionary *body = @{ 105 | @"error": error ? error.localizedDescription : [NSNull null], 106 | @"invitationIds": invitationIds ? invitationIds : [NSNull null] 107 | }; 108 | 109 | [self.bridge.eventDispatcher sendAppEventWithName:@"googleAppInviteIds" body:body]; 110 | } 111 | 112 | - (void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)user withError:(NSError *)error { 113 | 114 | if (error != Nil) { 115 | return [self.bridge.eventDispatcher sendAppEventWithName:@"googleSignInError" 116 | body:@{@"error": error.description}]; 117 | } 118 | 119 | NSDictionary *body = @{ 120 | @"name": user.profile.name, 121 | @"email": user.profile.email, 122 | @"accessToken": user.authentication.accessToken, 123 | @"accessTokenExpirationDate": [NSNumber numberWithDouble:user.authentication.accessTokenExpirationDate.timeIntervalSinceNow] 124 | }; 125 | 126 | return [self.bridge.eventDispatcher sendAppEventWithName:@"googleSignIn" body:body]; 127 | } 128 | 129 | - (void) signInWillDispatch:(GIDSignIn *)signIn error:(NSError *)error { 130 | return [self.bridge.eventDispatcher sendAppEventWithName:@"googleSignInWillDispatch" 131 | body:@{}]; 132 | } 133 | 134 | - (void)signIn:(GIDSignIn *)signIn didDisconnectWithUser:(GIDGoogleUser *)user withError:(NSError *)error { 135 | NSLog(@"Disconnect"); 136 | } 137 | 138 | - (void) signIn:(GIDSignIn *)signIn presentViewController:(UIViewController *)viewController { 139 | UIViewController *rootViewController = [[[[UIApplication sharedApplication]delegate] window] rootViewController]; 140 | [rootViewController presentViewController:viewController animated:true completion:nil]; 141 | } 142 | 143 | - (void) signIn:(GIDSignIn *)signIn dismissViewController:(UIViewController *)viewController { 144 | [viewController dismissViewControllerAnimated:true completion:nil]; 145 | } 146 | 147 | @end 148 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.1" 6 | 7 | defaultConfig { 8 | minSdkVersion 16 9 | targetSdkVersion 22 10 | versionCode 1 11 | versionName "1.0" 12 | ndk { 13 | abiFilters "armeabi-v7a", "x86" 14 | } 15 | } 16 | } 17 | 18 | dependencies { 19 | compile fileTree(include: ['*.jar'], dir: 'libs') 20 | compile "com.android.support:appcompat-v7:23.0.1" 21 | compile 'com.facebook.react:react-native:0.14.+' 22 | compile 'com.google.android.gms:play-services-appinvite:8.3.0' 23 | } 24 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | -------------------------------------------------------------------------------- /android/src/main/java/com/slowpath/googleappinvites/RNGoogleAppInvitesModule.java: -------------------------------------------------------------------------------- 1 | package com.slowpath.googleappinvites; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.net.Uri; 6 | 7 | import com.facebook.react.modules.core.DeviceEventManagerModule; 8 | import com.facebook.react.bridge.NativeModule; 9 | import com.facebook.react.bridge.ReactApplicationContext; 10 | import com.facebook.react.bridge.ReactContext; 11 | import com.facebook.react.bridge.ReactContextBaseJavaModule; 12 | import com.facebook.react.bridge.ReactMethod; 13 | 14 | import com.google.android.gms.common.ConnectionResult; 15 | import com.google.android.gms.appinvite.AppInviteInvitation; 16 | import com.google.android.gms.appinvite.AppInvite; 17 | import com.google.android.gms.common.api.GoogleApiClient; 18 | import com.google.android.gms.common.ConnectionResult; 19 | import com.google.android.gms.common.GooglePlayServicesUtil; 20 | 21 | import javax.annotation.Nullable; 22 | 23 | import com.facebook.react.bridge.Arguments; 24 | import com.facebook.react.bridge.WritableMap; 25 | import com.facebook.react.bridge.WritableArray; 26 | 27 | public class RNGoogleAppInvitesModule extends ReactContextBaseJavaModule { 28 | public static final int RC_APP_INVITES_IN = 9002; 29 | private static final int RESULT_OK = -1; 30 | 31 | private Activity _activity; 32 | private static ReactApplicationContext _context; 33 | 34 | public RNGoogleAppInvitesModule(ReactApplicationContext _reactContext, Activity activity) { 35 | super(_reactContext); 36 | _context = _reactContext; 37 | _activity = activity; 38 | } 39 | 40 | @Override 41 | public String getName() { 42 | return "RNGoogleAppInvites"; 43 | } 44 | 45 | public static void invitationsSentSuccessfully(String[] ids) { 46 | WritableMap params = Arguments.createMap(); 47 | WritableArray paramsIds = Arguments.fromArray(ids); 48 | params.putArray("ids", paramsIds); 49 | sendEvent(_context, "googleAppInviteIds", params); 50 | } 51 | 52 | public static void invitationsFailedOrCanceled() { 53 | WritableMap params = Arguments.createMap(); 54 | params.putString("message", "Sending failed or it was canceled"); 55 | sendEvent(_context, "googleAppInvitesError", params); 56 | } 57 | 58 | @ReactMethod 59 | public void init() { 60 | _activity.runOnUiThread(new Runnable() { 61 | @Override 62 | public void run() { 63 | new GoogleApiClient.Builder(_activity.getBaseContext()) 64 | .addApi(AppInvite.API) 65 | //.enableAutoManage(_activity, _activity.getBaseContext()) 66 | .build(); 67 | } 68 | }); 69 | } 70 | 71 | @ReactMethod 72 | public void invite(String message, String title, String deepLink) { 73 | _activity.runOnUiThread(new Runnable() { 74 | private String _message; 75 | private String _title; 76 | private String _deepLink; 77 | private Activity _activity; 78 | 79 | public Runnable init(String message, String title, String deepLink, Activity activity) { 80 | _message = message; 81 | _title = title; 82 | _deepLink = deepLink; 83 | _activity = activity; 84 | return (this); 85 | } 86 | 87 | @Override 88 | public void run() { 89 | Intent intent = new AppInviteInvitation.IntentBuilder(_title) 90 | .setMessage(_message) 91 | .setDeepLink(Uri.parse(_deepLink)) 92 | .build(); 93 | _activity.startActivityForResult(intent, RC_APP_INVITES_IN); 94 | } 95 | }.init(message, title, deepLink, _activity)); 96 | } 97 | 98 | public static void onActivityResult(int resultCode, Intent data) { 99 | if (resultCode == RESULT_OK) { 100 | String[] ids = AppInviteInvitation.getInvitationIds(resultCode, data); 101 | invitationsSentSuccessfully(ids); 102 | } else { 103 | // Sending failed or it was canceled, show failure message to the user 104 | invitationsFailedOrCanceled(); 105 | } 106 | } 107 | 108 | private static void sendEvent(ReactContext reactContext, 109 | String eventName, 110 | @Nullable WritableMap params) { 111 | reactContext 112 | .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) 113 | .emit(eventName, params); 114 | } 115 | 116 | } 117 | -------------------------------------------------------------------------------- /android/src/main/java/com/slowpath/googleappinvites/RNGoogleAppInvitesPackage.java: -------------------------------------------------------------------------------- 1 | package com.slowpath.googleappinvites; 2 | 3 | import android.app.Activity; 4 | 5 | import com.facebook.react.ReactPackage; 6 | import com.facebook.react.bridge.NativeModule; 7 | import com.facebook.react.bridge.ReactApplicationContext; 8 | import com.facebook.react.uimanager.ViewManager; 9 | import com.facebook.react.bridge.JavaScriptModule; 10 | 11 | import java.util.List; 12 | import java.util.ArrayList; 13 | import java.util.Collections; 14 | 15 | import com.slowpath.googleappinvites.RNGoogleAppInvitesModule; 16 | 17 | public class RNGoogleAppInvitesPackage implements ReactPackage { 18 | private Activity _activity; 19 | 20 | public RNGoogleAppInvitesPackage(Activity activity) { 21 | super(); 22 | _activity = activity; 23 | } 24 | 25 | @Override 26 | public List createNativeModules(ReactApplicationContext reactContext) { 27 | List modules = new ArrayList<>(); 28 | 29 | modules.add(new RNGoogleAppInvitesModule(reactContext, _activity)); 30 | 31 | return modules; 32 | } 33 | 34 | @Override 35 | public List> createJSModules() { 36 | return Collections.emptyList(); 37 | } 38 | 39 | @Override 40 | public List createViewManagers(ReactApplicationContext reactContext) { 41 | return Collections.emptyList(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var { 2 | NativeModules: { 3 | RNGoogleAppInvites 4 | } 5 | } = require('react-native'); 6 | 7 | module.exports = RNGoogleAppInvites; 8 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-google-app-invites", 3 | "version": "0.2.6", 4 | "description": "Google App Invites for your react native applications", 5 | "main": "index", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [ 10 | "react-component", 11 | "react-native", 12 | "google app invites", 13 | "google invites", 14 | "ios", 15 | "android" 16 | ], 17 | "author": { 18 | "name": "Ladislav Martincik", 19 | "email": "ladislav.martincik@gmail.com", 20 | "url": "https://github.com/martincik" 21 | }, 22 | "repository": { 23 | "type": "git", 24 | "url": "https://github.com/slowpath/react-native-google-app-invites" 25 | }, 26 | "bugs": { 27 | "url": "https://github.com/slowpath/react-native-google-app-invites/issues" 28 | }, 29 | "homepage": "https://github.com/slowpath/react-native-google-app-invites", 30 | "peerDependencies": { 31 | "react-native": ">= 0.14" 32 | }, 33 | "license": "MIT" 34 | } 35 | --------------------------------------------------------------------------------