-
Notifications
You must be signed in to change notification settings - Fork 4
/
SignInWithAppleButton.tsx
76 lines (70 loc) · 1.72 KB
/
SignInWithAppleButton.tsx
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import React from 'react';
import {
requireNativeComponent,
StyleProp,
StyleSheet,
Text,
View,
ViewStyle,
} from 'react-native';
import { SignInWithApple } from './SignInWithApple';
import {
ButtonStyle,
ButtonType,
AuthScope,
AuthorizationCredentials,
AuthorizationError,
} from './Types';
export interface SignInButtonProps {
buttonStyle: ButtonStyle;
buttonType: ButtonType;
scopes: [AuthScope];
state?: String;
style?: StyleProp<ViewStyle>;
onAuthorizationSuccess: (credentials: AuthorizationCredentials) => void;
onAuthorizationError: (error: AuthorizationError) => void;
}
export const SignInButton: React.FC<SignInButtonProps> = props => {
async function onPress() {
try {
const [response] = await SignInWithApple.authorize(
props.scopes,
props.state
);
props.onAuthorizationSuccess(response);
} catch (e) {
props.onAuthorizationError(e);
}
}
return SignInWithApple.constants.isAvailable ? (
<NativeView
buttonStyleRawValue={props.buttonStyle}
buttonTypeRawValue={props.buttonType}
onPress={onPress}
style={[DEFAULT_APPLE_ID_BUTTON_STYLE, props.style]}
/>
) : (
<StupButton />
);
};
const StupButton: React.FC = () => (
<View
style={{
borderWidth: StyleSheet.hairlineWidth,
borderColor: 'red',
borderRadius: 8,
paddingHorizontal: 20,
paddingVertical: 10,
}}
>
<Text style={{ color: 'red', textAlign: 'center' }}>
"Sign in with Apple" is available on iOS 13.0 and newer
</Text>
</View>
);
const NativeView = requireNativeComponent('SingInButtonView');
const DEFAULT_APPLE_ID_BUTTON_STYLE = {
minWidth: 100,
height: 44,
width: '100%',
};