-
Notifications
You must be signed in to change notification settings - Fork 25
/
index.js
42 lines (35 loc) · 1.38 KB
/
index.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
import React from 'react';
import { TouchableOpacity, Text, NativeModules, requireNativeComponent, Platform } from 'react-native';
const { AppleAuthentication } = NativeModules;
export const RNSignInWithAppleButton = requireNativeComponent('RNCSignInWithAppleButton');
export const SignInWithAppleButton = ({ buttonText = '', callBack, buttonStyle = { borderRadius: 5, justifyContent: 'center', alignItems: 'center', backgroundColor: 'black' }, textStyle = { fontWeight: 'bold', fontSize: 18, color: "white", textAlign: 'center', marginTop: 10, marginBottom: 10, marginHorizontal: 20 } }) => {
if (Platform.OS === 'ios') {
if (buttonText !== '') {
return <TouchableOpacity style={buttonStyle} onPress={async () => {
await appleAuth(callBack);
}}
>
<Text style={textStyle}>
{buttonText}
</Text>
</TouchableOpacity>
} else {
return <RNSignInWithAppleButton style={buttonStyle} onPress={async () => {
await appleAuth(callBack);
}}
/>
}
} else {
return null
}
}
const appleAuth = async (callBack) => {
await AppleAuthentication.requestAsync({
requestedScopes: [AppleAuthentication.Scope.FULL_NAME, AppleAuthentication.Scope.EMAIL],
}).then((response) => {
callBack(response) //Display response
}, (error) => {
callBack(error) //Display error
});
}
export default AppleAuthentication;