-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
105 lines (99 loc) · 2.92 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
import React, {useEffect, useState} from 'react';
import {
Button,
HostComponent,
NativeEventEmitter,
NativeModules,
PermissionsAndroid,
Platform,
requireNativeComponent,
Text,
View,
ViewProps,
} from 'react-native';
const PassioSDK = NativeModules.PassioPlatformSDKBridge;
const PassioCameraView = requireNativeComponent(
'PassioCameraView',
) as HostComponent<ViewProps>;
function App(): JSX.Element {
const [sdkStatus, setSdkStatus] = useState<string>();
const [isDetecting, setIsDetecting] = useState(false);
const [candidate, setCandidate] = useState<string>();
useEffect(() => {
const requestCameraPermission = async () => {
if (Platform.OS === 'ios') {
return;
}
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.CAMERA,
{
title: 'Cool Photo App Camera Permission',
message:
'Cool Photo App needs access to your camera ' +
'so you can take awesome pictures.',
buttonNeutral: 'Ask Me Later',
buttonNegative: 'Cancel',
buttonPositive: 'OK',
},
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log('You can use the camera');
} else {
console.log('Camera permission denied');
}
} catch (err) {
console.warn(err);
}
};
requestCameraPermission();
}, []);
useEffect(() => {
PassioSDK.configure(
'license-key', // your license key here
'project-id', // your projectID here
1, // set debugMode here
true, // set autoUpdate as true
).then((result: string) => {
console.log({result});
setSdkStatus(result);
});
const PassioSDKListener = new NativeEventEmitter(PassioSDK);
PassioSDKListener.addListener('onDetectionCandidates', setCandidate);
return () => PassioSDK.removeListeners();
}, []);
return (
<View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
{sdkStatus === 'isReadyForDetection' ? (
<>
<PassioCameraView style={{flex: 1, width: '100%'}} />
<View
style={{
position: 'absolute',
width: '100%',
justifyContent: 'center',
alignItems: 'center',
bottom: 100,
}}>
<Button
title={!isDetecting ? 'Start' : 'Stop'}
onPress={() => {
console.log({PassioSDK});
if (!isDetecting) {
PassioSDK.startDetection();
} else {
PassioSDK.stopDetection();
}
setIsDetecting(!isDetecting);
}}
/>
<Text>{`Candidate: ${candidate}`}</Text>
</View>
</>
) : (
<Text>RN Passio Platform SDK</Text>
)}
</View>
);
}
export default App;