/**
 * @providesModule react-native-digits
 * @flow
 */
'use strict';

var { NativeModules } = require('react-native');
var NativeRNDigits = NativeModules.RNDigits;
var invariant = require('invariant');

/**
 * High-level docs for the RNDigits iOS API can be written here.
 */

var RNDigits = {
  view(callback) {
    NativeRNDigits.view(callback);
  },

  logout() {
    NativeRNDigits.logout();
  }
}

module.exports = RNDigits;

/**
 * @providesModule react-native-digits
 * @flow
 */
'use strict';

import React, { Component, NativeModules, PropTypes } from 'react-native'
const { RNDigits } = NativeModules

export default class Digits extends Component {
  componentWillReceiveProps(props) {
    if (props.visible && this.props.visible == false) {
      this.show()
    }
  }

  show() {
    RNDigits.view((err, session) => {
      if (err) {
        this.props.onError(err)
      } else {
        this.props.onLogin(session)
      }
    })
  }

  render() {
    return false
  }
}

Digits.propTypes = {
  onError: PropTypes.func,
  onLogin: PropTypes.func.isRequired,
  visible: PropTypes.bool.isRequired,
}

Digits.defaultProps = {
  onError: (err) => console.warn(err),
  visible: false,
}

Refactor api into a react class
Refactor api into a react class
