forked from JeanLebrument/react-native-fabric-digits
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DigitsLoginButton.js
47 lines (40 loc) · 1.3 KB
/
DigitsLoginButton.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import React, { Component } from 'react';
import { NativeModules, Text, TouchableHighlight } from 'react-native';
class DigitsLoginButton extends Component {
constructor(props) {
super(props);
this.buttonPressed = this.buttonPressed.bind(this);
this.getSessionDetails = this.getSessionDetails.bind(this);
}
getSessionDetails(callback) {
NativeModules.DigitsManager.sessionDetails((error, sessionDetails) => {
if (error) {
console.error(error);
} else {
callback(sessionDetails);
}
});
}
buttonPressed() {
NativeModules.DigitsManager.launchAuthentication(this.props.options).then((responseData) => {
console.log("[Digits] Login Successful", responseData);
this.props.completion(null, responseData);
}).catch((error) => {
if(error && error.code != 1){
console.error("[Digits] Login Error", error);
}
this.props.completion(error, null);
});
}
render() {
return (
<TouchableHighlight style={this.props.buttonStyle} underlayColor={this.props.highlightColor} onPress={this.buttonPressed} >
<Text style={this.props.textStyle}>{this.props.text}</Text>
</TouchableHighlight>
);
}
}
DigitsLoginButton.defaultProps = {
highlightColor: 'black',
};
module.exports = DigitsLoginButton;