-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
130 lines (113 loc) · 3.2 KB
/
App.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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import React from 'react'
import {
Platform,
TouchableHighlight,
StyleSheet,
ScrollView,
View,
Text,
Image,
} from 'react-native'
import Zoom from 'react-native-facetec-zoom'
import deviceKeyIdentifier from './device-key-identifier'
const BigText = ({ children, style }) => <Text style={[styles.bigText, style]}>{children}</Text>
const Button = ({ children, ...props }) => (
<TouchableHighlight {...props} style={styles.button}>
<Text style={[styles.hugeText, styles.buttonText]}>{children}</Text>
</TouchableHighlight>
)
const prettify = (obj) => (obj ? JSON.stringify(obj, null, 2) : '')
// don't actually do this
const getFaceID = () => String(Math.random()).split('.')[1]
export default class App extends React.Component {
state = {}
init = async () => {
const { success, status } = await Zoom.initialize({
deviceKeyIdentifier,
showPreEnrollmentScreen: false,
showUserLockedScreen: false,
showRetryScreen: false,
topMargin: 200,
// sizeRatio: 0.7,
centerFrame: false,
returnBase64: false,
})
if (!success) {
// see constants.js SDKStatus for explanations of various
// reasons why initialize might not have gone through
throw new Error(`failed to init. SDK status: ${status}`)
}
this.initialized = true
}
enroll = async () => {
if (!this.initialized) await this.init()
const faceID = getFaceID()
this.setState({ faceID })
// launch Zoom's enrollment process
return Zoom.enroll({
id: faceID,
}).then(this.setResult, this.setError)
}
authenticate = async () => {
if (!this.initialized) await this.init()
// launch Zoom's enrollment process
return Zoom.authenticate({
id: this.state.faceID,
}).then(this.setResult, this.setError)
}
verifyLiveness = async () => {
if (!this.initialized) await this.init()
// launch Zoom's verification process
return Zoom.verifyLiveness().then(this.setResult, this.setError)
}
setResult = (result) => this.setState({ result })
setError = (error) => this.setState({ error })
render = () => {
return (
<View style={styles.container}>
<BigText>Operations:</BigText>
<Button onPress={this.verifyLiveness}>Verify Liveness</Button>
<Button onPress={this.enroll}>Enroll</Button>
{this.state.faceID && <Button onPress={this.authenticate}>Authenticate</Button>}
{this.state.result && (
<>
<BigText>Result:</BigText>
<ScrollView contentContainerStyle={styles.scrollContainer}>
<BigText>{prettify(this.state.result)}</BigText>
</ScrollView>
</>
)}
{this.state.error && (
<>
<BigText>Error:</BigText>
<BigText>{prettify(this.state.error)}</BigText>
</>
)}
</View>
)
}
}
const styles = StyleSheet.create({
scrollContainer: {},
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
button: {
padding: 10,
},
buttonText: {
color: 'blue',
fontSize: 30,
},
bigText: {
fontSize: 20,
},
image: {
flex: 1,
resizeMode: 'contain',
minWidth: 300,
minHeight: 300,
},
})