-
Notifications
You must be signed in to change notification settings - Fork 2
/
App.tsx
184 lines (173 loc) · 4.75 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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* Generated with the TypeScript template
* https://github.com/react-native-community/react-native-template-typescript
*
* @format
*/
import React, {useState} from 'react';
import VeryfiLens from '@veryfi/react-native-veryfi-lens';
import {
VERYFI_CLIENT_ID,
VERYFI_USERNAME,
VERYFI_API_KEY,
VERYFI_URL,
} from '@env';
import {
Image,
NativeEventEmitter,
SafeAreaView,
ScrollView,
StatusBar,
StyleSheet,
Text,
TouchableOpacity,
View,
} from 'react-native';
const veryfiLensCredentials = {
url: VERYFI_URL,
clientId: VERYFI_CLIENT_ID,
userName: VERYFI_USERNAME,
apiKey: VERYFI_API_KEY,
};
const veryfiLensSettings = {
blurDetectionIsOn: true,
autoLightDetectionIsOn: false,
documentTypes: ['receipt'],
showDocumentTypes: true,
dataExtractionEngine: 'api',
};
const VeryfiLensEmitter = new NativeEventEmitter(VeryfiLens.NativeModule);
const App = () => {
const [log, setLog] = useState(
" Here you will see JSON results from a scan's data extraction performed by the Veryfi API.\n\n Look carefully, there are 30+ fields (inc. line items) extracted and understood by Veryfi's AI.\n\n Before you begin, please find a receipt, bill or invoice. Then when ready, press the green COLLECT button below. This will start the Veryfi Lens camera used to capture, preprocess and prepared the document for real-time data extraction.\n\n If you need help, please contact [email protected]\n\n",
);
const [thumbnail, setThumbnail] = useState(
'https://avatars.githubusercontent.com/u/64030334?s=200&v=4',
);
const updateLog = (event: any) => {
setLog(_log => _log + '\n\n' + JSON.stringify(event, null, ' '));
if ('msg' in event && event.msg === 'img_original_path') {
setThumbnail(
_thumbnail => 'file://' + event.data + '?d=' + event.package_id,
);
VeryfiLens.getFileBase64(
event.data,
(error: any) => {
console.error(`Error found! ${error}`);
},
(dataBase64: any) => {
console.log(`dataBase64 ${dataBase64} returned`);
},
);
}
};
const setupListeners = () => {
VeryfiLensEmitter.removeAllListeners(VeryfiLens.Events.onVeryfiLensClose);
VeryfiLensEmitter.removeAllListeners(VeryfiLens.Events.onVeryfiLensUpdate);
VeryfiLensEmitter.removeAllListeners(VeryfiLens.Events.onVeryfiLensError);
VeryfiLensEmitter.removeAllListeners(VeryfiLens.Events.onVeryfiLensSuccess);
VeryfiLensEmitter.addListener(
VeryfiLens.Events.onVeryfiLensClose,
updateLog,
);
VeryfiLensEmitter.addListener(
VeryfiLens.Events.onVeryfiLensUpdate,
updateLog,
);
VeryfiLensEmitter.addListener(
VeryfiLens.Events.onVeryfiLensError,
updateLog,
);
VeryfiLensEmitter.addListener(
VeryfiLens.Events.onVeryfiLensSuccess,
updateLog,
);
};
const showCamera = () => {
setupListeners();
VeryfiLens.configureWithCredentials(
veryfiLensCredentials,
veryfiLensSettings,
() => {
VeryfiLens.showCamera();
},
);
};
return (
<SafeAreaView style={styles.background}>
<StatusBar barStyle={'dark-content'} />
<View style={styles.background}>
<Text style={styles.title}> {'Welcome to Veryfi Lens Demo'} </Text>
<Image style={styles.thumbnail} source={{uri: thumbnail}} />
<View style={styles.logBox}>
<ScrollView contentInsetAdjustmentBehavior="automatic">
<Text style={styles.logText}>{log}</Text>
</ScrollView>
</View>
<View style={styles.veryfiButton}>
<TouchableOpacity onPress={showCamera}>
<Text style={styles.textBoldCenter}>COLLECT</Text>
</TouchableOpacity>
</View>
</View>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
background: {
backgroundColor: '#FFFFFF',
flex: 1,
},
sectionTitle: {
fontSize: 24,
fontWeight: '600',
},
logBox: {
margin: 16,
backgroundColor: '#ADD8E6',
borderRadius: 8,
overflow: 'hidden',
flex: 1,
},
logText: {
margin: 16,
textAlign: 'left',
fontSize: 17,
fontWeight: '300',
},
veryfiButton: {
borderColor: '#3FCD8D',
borderWidth: 2,
width: 80,
height: 80,
borderRadius: 16,
overflow: 'hidden',
alignSelf: 'center',
justifyContent: 'center',
alignItems: 'center',
},
title: {
marginTop: 32,
alignSelf: 'center',
fontSize: 25,
fontWeight: '500',
},
container: {
paddingTop: 50,
},
thumbnail: {
alignSelf: 'center',
width: 200,
height: 200,
},
textBoldCenter: {
fontSize: 14,
fontWeight: 'bold',
alignSelf: 'center',
marginTop: 2,
},
});
export default App;