react-native-luzgan-twitter-signin

0.0.4 • Public • Published

npm version

Fork of https://github.com/GoldenOwlAsia/react-native-twitter-signin

Forked to add promise support and exceptions support. As well as making it working for RN0.29+.

Also - in opposition to GoldenOwl twitter signin, this plugin will fail if email is not available to you. Note that this is not standard, you can login without email - I've made it this way to support our app.

Table of contents

Prerequisites

Since Twitter Kit can only be used via Fabric, make sure you install Fabric properly:

Fabric will use your Twitter accounts to generate API keys and tokens therefore you have to redo this every time you change your Twitter credentials.

Setup

Firstly, install the npm package:

npm install react-native-luzgan-twitter-signin --save

iOS

It is pretty simple to install it for iOS:

  • Open you Xcode IDE
  • In Libraries choose Add files... and add the 2 files ios/TwitterSignin/TwitterSignin.h and ios/TwitterSignin/TwitterSignin.m in your node_modules/react-native-twitter-signin folder
  • Rebuild your project to make sure no build error

Android

On Android, it will use Gradle so all you need to do is to point to the correct project location:

  • In your ${project_dir}/android/settings.gradle add this:

    include ':react-native-luzgan-twitter-signin'
    project(':react-native-luzgan-twitter-signin').projectDir = new File(rootProject.projectDir,'../node_modules/react-native-luzgan-twitter-signin/android')
    
  • In your ${project_dir}/android/app/build.gradle add this:

    depedencies {
       ...
       compile project(':react-native-luzgan-twitter-signin')
       ...
    }
    
  • RN0.29+ In you MainApplication.java makes use of the package as following:

        [...]
        //add in the imports 
        import com.luzgan.twittersignin.TwitterSigninPackage;
        [...]
        /**
        * A list of packages used by the app. If the app uses additional views
        * or modules besides the default ones, add more packages here.
        */
        @Override
        protected List<ReactPackage> getPackages() {
           return Arrays.<ReactPackage>asList(
             new MainReactPackage(),
             new TwitterSigninPackage() //Add that 
           );
         }

Keeps in mind that all the configure is for your build tools to recognise the files. So open your Xcode and Android Studio to try making builds and make sure they pass.

Usage

  • Import your native module as follow:
 
        import React from 'react-native';
        var {
          NativeModules
          } = React;
        const { TwitterSignin } = NativeModules;
        class TwitterButton extends SocialButton {
          _twitterSignIn() {
            TwitterSignin.logIn({TWITTER_COMSUMER_KEY}, {TWITTER_CONSUMER_SECRET})
            .then((data) => {
             //use data
            }).catch((err) => {
             //handle err
            });
          }
          render() {
            return (
              <Icon name='social-twitter' size={32} color='white' style={styles.icon} onPress={this._twitterSignIn.bind(this)}/>
            );
          }
        };

Copyright and license

Code and documentation copyright 2016 Lukasz Holc. Code released under the MIT license.

Package Sidebar

Install

npm i react-native-luzgan-twitter-signin

Weekly Downloads

103

Version

0.0.4

License

MIT

Last publish

Collaborators

  • luzgan