/ReactNative-Demo

This a demo that shows how to integrate Gigya Registration as a Service and Social Login using React Native. This code repository is provided on an "as-is" basis for demonstration purposes. Please do not contact Gigya support for issues or assistance in regards to this project. For further information on the Gigya platform and APIs, please reference:

Primary LanguageJavaScript

Table of Contents

About this project
Requirements
Running this demo
Integrating Gigya with existing projects

Gigya Integration with React Native Gigya Integration with React Native

About this project

This is a simple demo to illustrate Gigya Integration with React Native. Integration is done via Native Modules. The idea is to create a React RCTBridgeModule for Gigya's available Mobile SDKs (iOS and Android), and use this bridge to communicate between React Native (JS) and Native (SDKs).

Currently, this demo includes sample flows in iOS and Android for:

  • Native site (Email/Password) login
  • Native site (Email/Password) registration
  • Login/Registration via Screen-Sets
  • Native password reset
  • Social Login w/ Facebook, Google and Twitter
  • Update Profile via Screen-Sets
  • Comments via comments.commentsUI
  • Native Add Connection (Add social account)
  • Logout

Requirements

brew install node
brew install watchman
npm install -g react-native-cli

See React Native official documentation for more information on setting up your environment

Running this demo

cd ReactNative-Demo
npm install
# or
yarn install

If Yarn was installed when the project was initialized, then dependencies will have been installed via Yarn, and you should probably use it to run these commands as well. Unlike dependency installation, command running syntax is identical for Yarn and NPM at the time of this writing.

npm start

Runs your app in development mode.

Open it in the Expo app on your phone to view it. It will reload if you save edits to your files, and you will see build errors and logs in the terminal.

Sometimes you may need to reset or clear the React Native packager's cache. To do so, you can pass the --reset-cache flag to the start script:

npm start -- --reset-cache
# or
yarn start -- --reset-cache

npm test

Runs the jest test runner on your tests.

npm run ios

Like npm start, but also attempts to open your app in the iOS Simulator if you're on a Mac and have it installed.

Note: The iOS project is configured with CocoaPods - and calls Gigya, Facebook and Google native SDKs. Run pod install from terminal to install libraries.

npm run android

Like npm start, but also attempts to open your app on a connected Android device or emulator. Requires an installation of Android build tools (see React Native docs for detailed setup). We also recommend installing Genymotion as your Android emulator. Once you've finished setting up the native build environment, there are two options for making the right copy of adb available to Create React Native App:

Using Android Studio's adb
  1. Make sure that you can run adb from your terminal.
  2. Open Genymotion and navigate to Settings -> ADB. Select “Use custom Android SDK tools” and update with your Android SDK directory.
Using Genymotion's adb
  1. Find Genymotion’s copy of adb. On macOS for example, this is normally /Applications/Genymotion.app/Contents/MacOS/tools/.
  2. Add the Genymotion tools directory to your path (instructions for Mac, Linux, and Windows).
  3. Make sure that you can run adb from your terminal.

Integrating Gigya with existing projects

When building an app in React Native, it is recommended to use Gigya's iOS and Android SDKs to interact with Gigya API. Using third-party SDKs in React Native it’s pretty straightforward thanks to Native Modules (iOS - Android). Native Modules allow reusing existing Objective-C, Swift or Java code without having to reimplement it in JavaScript.

To integrate Gigya with an existing React Native project, follow these instructions:

iOS

Obtain Your Gigya API Key and enable Mobile or Desktop Client Applications API Access. Refer to the 'Gigya Setup' section.

In your React Native iOS Xcode Project:

  1. Integrate the Gigya SDK. Refer to the 'Getting started' and 'Initialization' sections.
  2. Add Facebook and Google Native Login if you want to offer log in via Facebook/Google. Refer to Twitter and Line sections for corresponding instructions.
  3. Create a new Objetive-C class, which will serve as a bridge between your React code and Gigya's native SDK. Use GigyaBridge.h and GigyaBridge.m as a start point to build your bridge.

Android

Obtain Your Gigya API Key and enable Mobile or Desktop Client Applications API Access. Refer to the 'Gigya Setup' section.

In your React Native Android Project:

  1. Integrate the Gigya Android SDK. Refer to the 'Download', 'Add to AndroidManifest.xml' and 'Initialization' sections.
  2. Add Facebook and Google Native Login if you want to offer log in via Facebook/Google. Refer to Line section for corresponding instructions.
  3. Create two new classes, which will serve as a bridge between your React code and Gigya's native SDK. Use GigyaBridge.java and GigyaBridgePackage.java as a start point to build your bridge.

JavaScript

Finally, call your bridge from the React Native code:

// Importing the bridge
import { NativeEventEmitter, NativeModules } from 'react-native';
const Gigya = NativeModules.GigyaBridge;

// Subscribing to the bridge events
this.gigyaManagerEmitter = new NativeEventEmitter(Gigya);
this.accountDidLoginSubscription = this.gigyaManagerEmitter.addListener('AccountDidLogin', this.onAccountDidLogin);

// Calling bridge methods
Gigya.initBridge();
Gigya.isSessionValid(this.onIsSessionValidCompleted);

Other resources

Bootstrapped from React Native

This project was bootstrapped with Create React Native App.