/
App.tsx
84 lines (72 loc) · 1.95 KB
/
App.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
77
78
79
80
81
82
83
84
import React from 'react'
import {
View,
Text,
Alert,
Button,
StyleSheet,
SafeAreaView
} from 'react-native'
import GoogleRecaptcha, {
GoogleRecaptchaSize,
GoogleRecaptchaToken,
GoogleRecaptchaProps,
GoogleRecaptchaRefAttributes
} from 'react-native-google-recaptcha'
const BASE_URL = 'http://localhost:3000'
const SITE_KEY = '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI'
type ExampleProps = Partial<GoogleRecaptchaProps> & { title: string }
const Example: React.FC<ExampleProps> = (props: ExampleProps) => {
const { title, ...recaptchaProps } = props
const recaptchaRef = React.useRef<GoogleRecaptchaRefAttributes>(null)
const handleSendForm = () => {
recaptchaRef.current?.open()
}
const handleVerify = (token: GoogleRecaptchaToken) => {
Alert.alert(title, `${token}`)
}
const handleError = (error: unknown) => {
Alert.alert('Recaptcha Error', JSON.stringify(error))
}
return (
<View style={styles.container}>
<Text style={styles.title}>{title}</Text>
<GoogleRecaptcha
ref={recaptchaRef}
baseUrl={BASE_URL}
siteKey={SITE_KEY}
onError={handleError}
onVerify={handleVerify}
{...recaptchaProps}
/>
<Button title="Send Form" onPress={handleSendForm} />
</View>
)
}
const App = () => (
<SafeAreaView style={{ flex: 1 }}>
<Example title="Size: normal" />
<View style={styles.bottomDivider} />
<Example title="Size: invisible" size={GoogleRecaptchaSize.INVISIBLE} />
<View style={styles.bottomDivider} />
<Example title="Size: compact" size={GoogleRecaptchaSize.COMPACT} />
</SafeAreaView>
)
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#292524'
},
title: {
color: '#FFFFFF',
fontWeight: 'bold',
marginBottom: 10
},
bottomDivider: {
borderBottomWidth: 1,
borderBottomColor: '#DDDDDD'
}
})
export default App