@ha_tecno/live-id-sdk 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (217) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +323 -0
  3. package/android/build.gradle +94 -0
  4. package/android/gradle.properties +5 -0
  5. package/android/src/main/AndroidManifest.xml +4 -0
  6. package/android/src/main/AndroidManifestNew.xml +2 -0
  7. package/android/src/main/java/com/liveidsdk/LiveIdSdkModule.kt +25 -0
  8. package/android/src/main/java/com/liveidsdk/LiveIdSdkPackage.kt +17 -0
  9. package/ios/LiveIdSdk-Bridging-Header.h +2 -0
  10. package/ios/LiveIdSdk.mm +14 -0
  11. package/ios/LiveIdSdk.swift +8 -0
  12. package/lib/commonjs/assets/arrow.png +0 -0
  13. package/lib/commonjs/assets/exampleInstructionWithBorder.jpeg +0 -0
  14. package/lib/commonjs/assets/exampleInstructionWithoutFinger.jpeg +0 -0
  15. package/lib/commonjs/assets/ic_redness_capture_tip.png +0 -0
  16. package/lib/commonjs/assets/logo.png +0 -0
  17. package/lib/commonjs/components/CameraConfigInfos/index.js +21 -0
  18. package/lib/commonjs/components/CameraConfigInfos/index.js.map +1 -0
  19. package/lib/commonjs/components/CameraConfigInfos/styles.js +19 -0
  20. package/lib/commonjs/components/CameraConfigInfos/styles.js.map +1 -0
  21. package/lib/commonjs/components/DeviceNullDisplay/index.js +59 -0
  22. package/lib/commonjs/components/DeviceNullDisplay/index.js.map +1 -0
  23. package/lib/commonjs/components/ErrorDisplay/index.js +59 -0
  24. package/lib/commonjs/components/ErrorDisplay/index.js.map +1 -0
  25. package/lib/commonjs/components/Gabarito/index.js +19 -0
  26. package/lib/commonjs/components/Gabarito/index.js.map +1 -0
  27. package/lib/commonjs/components/Gabarito/styles.js +30 -0
  28. package/lib/commonjs/components/Gabarito/styles.js.map +1 -0
  29. package/lib/commonjs/components/Toast/Toast.js +66 -0
  30. package/lib/commonjs/components/Toast/Toast.js.map +1 -0
  31. package/lib/commonjs/components/WaitingForResult/index.js +24 -0
  32. package/lib/commonjs/components/WaitingForResult/index.js.map +1 -0
  33. package/lib/commonjs/components/WaitingForResult/styles.js +32 -0
  34. package/lib/commonjs/components/WaitingForResult/styles.js.map +1 -0
  35. package/lib/commonjs/index.js +34 -0
  36. package/lib/commonjs/index.js.map +1 -0
  37. package/lib/commonjs/screens/CadastroFinger/components/AjudaCadastro/index.js +49 -0
  38. package/lib/commonjs/screens/CadastroFinger/components/AjudaCadastro/index.js.map +1 -0
  39. package/lib/commonjs/screens/CadastroFinger/components/AjudaCadastro/styles.js +62 -0
  40. package/lib/commonjs/screens/CadastroFinger/components/AjudaCadastro/styles.js.map +1 -0
  41. package/lib/commonjs/screens/CadastroFinger/components/CameraCadastro/index.js +298 -0
  42. package/lib/commonjs/screens/CadastroFinger/components/CameraCadastro/index.js.map +1 -0
  43. package/lib/commonjs/screens/CadastroFinger/components/CameraCadastro/styles.js +54 -0
  44. package/lib/commonjs/screens/CadastroFinger/components/CameraCadastro/styles.js.map +1 -0
  45. package/lib/commonjs/screens/CadastroFinger/components/ImageDisplayScreen/index.js +44 -0
  46. package/lib/commonjs/screens/CadastroFinger/components/ImageDisplayScreen/index.js.map +1 -0
  47. package/lib/commonjs/screens/CadastroFinger/components/ImageDisplayScreen/styles.js +65 -0
  48. package/lib/commonjs/screens/CadastroFinger/components/ImageDisplayScreen/styles.js.map +1 -0
  49. package/lib/commonjs/screens/CadastroFinger/index.js +50 -0
  50. package/lib/commonjs/screens/CadastroFinger/index.js.map +1 -0
  51. package/lib/commonjs/screens/CadastroScreen/CadastroScreen.js +186 -0
  52. package/lib/commonjs/screens/CadastroScreen/CadastroScreen.js.map +1 -0
  53. package/lib/commonjs/screens/ProvaVidas/index.js +246 -0
  54. package/lib/commonjs/screens/ProvaVidas/index.js.map +1 -0
  55. package/lib/commonjs/screens/ProvaVidas/styles.js +93 -0
  56. package/lib/commonjs/screens/ProvaVidas/styles.js.map +1 -0
  57. package/lib/commonjs/screens/ValidadeFinger/index.js +216 -0
  58. package/lib/commonjs/screens/ValidadeFinger/index.js.map +1 -0
  59. package/lib/commonjs/screens/ValidadeFinger/styles.js +54 -0
  60. package/lib/commonjs/screens/ValidadeFinger/styles.js.map +1 -0
  61. package/lib/commonjs/services/index.js +145 -0
  62. package/lib/commonjs/services/index.js.map +1 -0
  63. package/lib/commonjs/types/screen.js +2 -0
  64. package/lib/commonjs/types/screen.js.map +1 -0
  65. package/lib/commonjs/utils/file.js +38 -0
  66. package/lib/commonjs/utils/file.js.map +1 -0
  67. package/lib/commonjs/utils/getConfigCamera.js +25 -0
  68. package/lib/commonjs/utils/getConfigCamera.js.map +1 -0
  69. package/lib/commonjs/utils/index.js +14 -0
  70. package/lib/commonjs/utils/index.js.map +1 -0
  71. package/lib/module/assets/arrow.png +0 -0
  72. package/lib/module/assets/exampleInstructionWithBorder.jpeg +0 -0
  73. package/lib/module/assets/exampleInstructionWithoutFinger.jpeg +0 -0
  74. package/lib/module/assets/ic_redness_capture_tip.png +0 -0
  75. package/lib/module/assets/logo.png +0 -0
  76. package/lib/module/components/CameraConfigInfos/index.js +13 -0
  77. package/lib/module/components/CameraConfigInfos/index.js.map +1 -0
  78. package/lib/module/components/CameraConfigInfos/styles.js +13 -0
  79. package/lib/module/components/CameraConfigInfos/styles.js.map +1 -0
  80. package/lib/module/components/DeviceNullDisplay/index.js +51 -0
  81. package/lib/module/components/DeviceNullDisplay/index.js.map +1 -0
  82. package/lib/module/components/ErrorDisplay/index.js +51 -0
  83. package/lib/module/components/ErrorDisplay/index.js.map +1 -0
  84. package/lib/module/components/Gabarito/index.js +11 -0
  85. package/lib/module/components/Gabarito/index.js.map +1 -0
  86. package/lib/module/components/Gabarito/styles.js +24 -0
  87. package/lib/module/components/Gabarito/styles.js.map +1 -0
  88. package/lib/module/components/Toast/Toast.js +58 -0
  89. package/lib/module/components/Toast/Toast.js.map +1 -0
  90. package/lib/module/components/WaitingForResult/index.js +17 -0
  91. package/lib/module/components/WaitingForResult/index.js.map +1 -0
  92. package/lib/module/components/WaitingForResult/styles.js +26 -0
  93. package/lib/module/components/WaitingForResult/styles.js.map +1 -0
  94. package/lib/module/index.js +7 -0
  95. package/lib/module/index.js.map +1 -0
  96. package/lib/module/screens/CadastroFinger/components/AjudaCadastro/index.js +41 -0
  97. package/lib/module/screens/CadastroFinger/components/AjudaCadastro/index.js.map +1 -0
  98. package/lib/module/screens/CadastroFinger/components/AjudaCadastro/styles.js +56 -0
  99. package/lib/module/screens/CadastroFinger/components/AjudaCadastro/styles.js.map +1 -0
  100. package/lib/module/screens/CadastroFinger/components/CameraCadastro/index.js +288 -0
  101. package/lib/module/screens/CadastroFinger/components/CameraCadastro/index.js.map +1 -0
  102. package/lib/module/screens/CadastroFinger/components/CameraCadastro/styles.js +48 -0
  103. package/lib/module/screens/CadastroFinger/components/CameraCadastro/styles.js.map +1 -0
  104. package/lib/module/screens/CadastroFinger/components/ImageDisplayScreen/index.js +36 -0
  105. package/lib/module/screens/CadastroFinger/components/ImageDisplayScreen/index.js.map +1 -0
  106. package/lib/module/screens/CadastroFinger/components/ImageDisplayScreen/styles.js +59 -0
  107. package/lib/module/screens/CadastroFinger/components/ImageDisplayScreen/styles.js.map +1 -0
  108. package/lib/module/screens/CadastroFinger/index.js +42 -0
  109. package/lib/module/screens/CadastroFinger/index.js.map +1 -0
  110. package/lib/module/screens/CadastroScreen/CadastroScreen.js +177 -0
  111. package/lib/module/screens/CadastroScreen/CadastroScreen.js.map +1 -0
  112. package/lib/module/screens/ProvaVidas/index.js +239 -0
  113. package/lib/module/screens/ProvaVidas/index.js.map +1 -0
  114. package/lib/module/screens/ProvaVidas/styles.js +87 -0
  115. package/lib/module/screens/ProvaVidas/styles.js.map +1 -0
  116. package/lib/module/screens/ValidadeFinger/index.js +206 -0
  117. package/lib/module/screens/ValidadeFinger/index.js.map +1 -0
  118. package/lib/module/screens/ValidadeFinger/styles.js +48 -0
  119. package/lib/module/screens/ValidadeFinger/styles.js.map +1 -0
  120. package/lib/module/services/index.js +131 -0
  121. package/lib/module/services/index.js.map +1 -0
  122. package/lib/module/types/screen.js +2 -0
  123. package/lib/module/types/screen.js.map +1 -0
  124. package/lib/module/utils/file.js +29 -0
  125. package/lib/module/utils/file.js.map +1 -0
  126. package/lib/module/utils/getConfigCamera.js +19 -0
  127. package/lib/module/utils/getConfigCamera.js.map +1 -0
  128. package/lib/module/utils/index.js +3 -0
  129. package/lib/module/utils/index.js.map +1 -0
  130. package/lib/typescript/src/components/CameraConfigInfos/index.d.ts +9 -0
  131. package/lib/typescript/src/components/CameraConfigInfos/index.d.ts.map +1 -0
  132. package/lib/typescript/src/components/CameraConfigInfos/styles.d.ts +11 -0
  133. package/lib/typescript/src/components/CameraConfigInfos/styles.d.ts.map +1 -0
  134. package/lib/typescript/src/components/DeviceNullDisplay/index.d.ts +11 -0
  135. package/lib/typescript/src/components/DeviceNullDisplay/index.d.ts.map +1 -0
  136. package/lib/typescript/src/components/ErrorDisplay/index.d.ts +11 -0
  137. package/lib/typescript/src/components/ErrorDisplay/index.d.ts.map +1 -0
  138. package/lib/typescript/src/components/Gabarito/index.d.ts +3 -0
  139. package/lib/typescript/src/components/Gabarito/index.d.ts.map +1 -0
  140. package/lib/typescript/src/components/Gabarito/styles.d.ts +21 -0
  141. package/lib/typescript/src/components/Gabarito/styles.d.ts.map +1 -0
  142. package/lib/typescript/src/components/Toast/Toast.d.ts +42 -0
  143. package/lib/typescript/src/components/Toast/Toast.d.ts.map +1 -0
  144. package/lib/typescript/src/components/WaitingForResult/index.d.ts +7 -0
  145. package/lib/typescript/src/components/WaitingForResult/index.d.ts.map +1 -0
  146. package/lib/typescript/src/components/WaitingForResult/styles.d.ts +24 -0
  147. package/lib/typescript/src/components/WaitingForResult/styles.d.ts.map +1 -0
  148. package/lib/typescript/src/index.d.ts +5 -0
  149. package/lib/typescript/src/index.d.ts.map +1 -0
  150. package/lib/typescript/src/screens/CadastroFinger/components/AjudaCadastro/index.d.ts +7 -0
  151. package/lib/typescript/src/screens/CadastroFinger/components/AjudaCadastro/index.d.ts.map +1 -0
  152. package/lib/typescript/src/screens/CadastroFinger/components/AjudaCadastro/styles.d.ts +55 -0
  153. package/lib/typescript/src/screens/CadastroFinger/components/AjudaCadastro/styles.d.ts.map +1 -0
  154. package/lib/typescript/src/screens/CadastroFinger/components/CameraCadastro/index.d.ts +16 -0
  155. package/lib/typescript/src/screens/CadastroFinger/components/CameraCadastro/index.d.ts.map +1 -0
  156. package/lib/typescript/src/screens/CadastroFinger/components/CameraCadastro/styles.d.ts +44 -0
  157. package/lib/typescript/src/screens/CadastroFinger/components/CameraCadastro/styles.d.ts.map +1 -0
  158. package/lib/typescript/src/screens/CadastroFinger/components/ImageDisplayScreen/index.d.ts +12 -0
  159. package/lib/typescript/src/screens/CadastroFinger/components/ImageDisplayScreen/index.d.ts.map +1 -0
  160. package/lib/typescript/src/screens/CadastroFinger/components/ImageDisplayScreen/styles.d.ts +54 -0
  161. package/lib/typescript/src/screens/CadastroFinger/components/ImageDisplayScreen/styles.d.ts.map +1 -0
  162. package/lib/typescript/src/screens/CadastroFinger/index.d.ts +16 -0
  163. package/lib/typescript/src/screens/CadastroFinger/index.d.ts.map +1 -0
  164. package/lib/typescript/src/screens/CadastroScreen/CadastroScreen.d.ts +14 -0
  165. package/lib/typescript/src/screens/CadastroScreen/CadastroScreen.d.ts.map +1 -0
  166. package/lib/typescript/src/screens/ProvaVidas/index.d.ts +14 -0
  167. package/lib/typescript/src/screens/ProvaVidas/index.d.ts.map +1 -0
  168. package/lib/typescript/src/screens/ProvaVidas/styles.d.ts +85 -0
  169. package/lib/typescript/src/screens/ProvaVidas/styles.d.ts.map +1 -0
  170. package/lib/typescript/src/screens/ValidadeFinger/index.d.ts +14 -0
  171. package/lib/typescript/src/screens/ValidadeFinger/index.d.ts.map +1 -0
  172. package/lib/typescript/src/screens/ValidadeFinger/styles.d.ts +44 -0
  173. package/lib/typescript/src/screens/ValidadeFinger/styles.d.ts.map +1 -0
  174. package/lib/typescript/src/services/index.d.ts +21 -0
  175. package/lib/typescript/src/services/index.d.ts.map +1 -0
  176. package/lib/typescript/src/types/screen.d.ts +6 -0
  177. package/lib/typescript/src/types/screen.d.ts.map +1 -0
  178. package/lib/typescript/src/utils/file.d.ts +3 -0
  179. package/lib/typescript/src/utils/file.d.ts.map +1 -0
  180. package/lib/typescript/src/utils/getConfigCamera.d.ts +14 -0
  181. package/lib/typescript/src/utils/getConfigCamera.d.ts.map +1 -0
  182. package/lib/typescript/src/utils/index.d.ts +3 -0
  183. package/lib/typescript/src/utils/index.d.ts.map +1 -0
  184. package/live-id-sdk.podspec +41 -0
  185. package/package.json +184 -0
  186. package/src/assets/arrow.png +0 -0
  187. package/src/assets/exampleInstructionWithBorder.jpeg +0 -0
  188. package/src/assets/exampleInstructionWithoutFinger.jpeg +0 -0
  189. package/src/assets/ic_redness_capture_tip.png +0 -0
  190. package/src/assets/logo.png +0 -0
  191. package/src/components/CameraConfigInfos/index.tsx +25 -0
  192. package/src/components/CameraConfigInfos/styles.ts +13 -0
  193. package/src/components/DeviceNullDisplay/index.tsx +59 -0
  194. package/src/components/ErrorDisplay/index.tsx +60 -0
  195. package/src/components/Gabarito/index.tsx +11 -0
  196. package/src/components/Gabarito/styles.ts +23 -0
  197. package/src/components/Toast/Toast.tsx +61 -0
  198. package/src/components/WaitingForResult/index.tsx +22 -0
  199. package/src/components/WaitingForResult/styles.ts +27 -0
  200. package/src/index.tsx +6 -0
  201. package/src/screens/CadastroFinger/components/AjudaCadastro/index.tsx +49 -0
  202. package/src/screens/CadastroFinger/components/AjudaCadastro/styles.ts +56 -0
  203. package/src/screens/CadastroFinger/components/CameraCadastro/index.tsx +356 -0
  204. package/src/screens/CadastroFinger/components/CameraCadastro/styles.ts +47 -0
  205. package/src/screens/CadastroFinger/components/ImageDisplayScreen/index.tsx +45 -0
  206. package/src/screens/CadastroFinger/components/ImageDisplayScreen/styles.ts +55 -0
  207. package/src/screens/CadastroFinger/index.tsx +56 -0
  208. package/src/screens/CadastroScreen/CadastroScreen.tsx +212 -0
  209. package/src/screens/ProvaVidas/index.tsx +308 -0
  210. package/src/screens/ProvaVidas/styles.ts +99 -0
  211. package/src/screens/ValidadeFinger/index.tsx +263 -0
  212. package/src/screens/ValidadeFinger/styles.ts +47 -0
  213. package/src/services/index.ts +143 -0
  214. package/src/types/screen.ts +5 -0
  215. package/src/utils/file.ts +30 -0
  216. package/src/utils/getConfigCamera.ts +45 -0
  217. package/src/utils/index.ts +3 -0
@@ -0,0 +1,212 @@
1
+ /* eslint-disable react-native/no-inline-styles */
2
+ import React, { useEffect, useState } from 'react';
3
+ import {
4
+ View,
5
+ Text,
6
+ TextInput,
7
+ TouchableOpacity,
8
+ StyleSheet,
9
+ Alert,
10
+ Image,
11
+ } from 'react-native';
12
+ import { cadastro } from '../../services';
13
+ import Modal, { type ModalProps } from 'react-native-modal';
14
+
15
+ import type { ScreenProps } from '../../types/screen';
16
+
17
+ interface CadastroScreenProps {
18
+ isVisible: boolean;
19
+ onCloseModal?: () => void;
20
+ onError?: (response?: any) => void;
21
+ onSuccess?: (response?: any) => void;
22
+ ModalParams?: ModalProps;
23
+ screenProps?: ScreenProps;
24
+ }
25
+
26
+ export const CadastroScreen: React.FC<CadastroScreenProps> = ({
27
+ isVisible = false,
28
+ onCloseModal,
29
+ onError,
30
+ onSuccess,
31
+ ModalParams,
32
+ }) => {
33
+ const [cpf, setCpf] = useState('');
34
+ const [nome, setNome] = useState('');
35
+ const [senha, setSenha] = useState('');
36
+ const [confirmarSenha, setConfirmarSenha] = useState('');
37
+
38
+ const generateRandomElevenDigits = () => {
39
+ let cpf = '';
40
+ for (let i = 0; i < 11; i++) {
41
+ cpf += Math.floor(Math.random() * 9);
42
+ }
43
+ return cpf;
44
+ };
45
+
46
+ const generateRandomName = () => {
47
+ // uma strin aleatória de 10 caracteres a 14 caracteres
48
+ let name = '';
49
+ const length = Math.floor(Math.random() * 5) + 10;
50
+ for (let i = 0; i < length; i++) {
51
+ name += String.fromCharCode(Math.floor(Math.random() * 26) + 97);
52
+ }
53
+ return name;
54
+ };
55
+
56
+ useEffect(() => {
57
+ generateRnadomUser();
58
+ }, []);
59
+
60
+ const generateRnadomUser = () => {
61
+ setCpf(generateRandomElevenDigits());
62
+ setNome(generateRandomName());
63
+ setSenha('123');
64
+ setConfirmarSenha('123');
65
+ };
66
+
67
+ const handleCadastro = async () => {
68
+ try {
69
+ if (senha === confirmarSenha) {
70
+ const response = await cadastro(cpf, nome, senha);
71
+
72
+ console.log(response);
73
+ var jsonString = JSON.stringify(response);
74
+ onSuccess && onSuccess(response);
75
+
76
+ onCloseModalHandler();
77
+ if (jsonString.includes('person_id')) {
78
+ if (response.finger === false) {
79
+ // openModal({
80
+ // type: 'ajuda',
81
+ // screenProps: {
82
+ // id: response.person_id,
83
+ // },
84
+ // });
85
+ } else {
86
+ // openModal({
87
+ // type: 'login',
88
+ // });
89
+ }
90
+ } else if (jsonString.includes('User exists')) {
91
+ Alert.alert('Usuário já cadastrado!');
92
+ // openModal({
93
+ // type: 'login',
94
+ // });
95
+ } else if (jsonString.includes('erro')) {
96
+ Alert.alert('Usuário não cadastrado', 'Por favor, cadastre-se!');
97
+ } else {
98
+ Alert.alert(
99
+ 'Erro',
100
+ 'Ocorreu um erro ao fazer o Cadastro. Por favor, tente novamente mais tarde.'
101
+ );
102
+ }
103
+ } else {
104
+ Alert.alert(
105
+ 'Erro',
106
+ 'As senhas não coincidem. Por favor, tente novamente.'
107
+ );
108
+ return;
109
+ }
110
+ } catch (error) {
111
+ onError && onError(error);
112
+ console.error(error);
113
+ }
114
+ };
115
+
116
+ const onCloseModalHandler = () => {
117
+ onCloseModal && onCloseModal();
118
+ generateRnadomUser();
119
+ };
120
+
121
+ return (
122
+ <Modal
123
+ style={{ margin: 0 }}
124
+ isVisible={isVisible}
125
+ swipeDirection="down"
126
+ propagateSwipe={true}
127
+ onSwipeComplete={onCloseModalHandler}
128
+ {...ModalParams}
129
+ >
130
+ <View style={styles.container}>
131
+ <Image source={require('../../assets/logo.png')} style={styles.logo} />
132
+ <Text style={styles.title}>Cadastro de usuário</Text>
133
+ <TextInput
134
+ style={styles.input}
135
+ placeholder="CPF"
136
+ placeholderTextColor="#000"
137
+ keyboardType="numeric"
138
+ value={cpf}
139
+ onChangeText={setCpf}
140
+ />
141
+ <TextInput
142
+ style={styles.input}
143
+ placeholder="Nome"
144
+ placeholderTextColor="#000"
145
+ value={nome}
146
+ onChangeText={setNome}
147
+ />
148
+ <TextInput
149
+ style={styles.input}
150
+ placeholder="Digite a senha"
151
+ placeholderTextColor="#000"
152
+ secureTextEntry={true}
153
+ value={senha}
154
+ onChangeText={(text) => setSenha(text)}
155
+ />
156
+ <TextInput
157
+ style={styles.input}
158
+ placeholderTextColor="#000"
159
+ placeholder="Digite a senha novamente"
160
+ secureTextEntry={true}
161
+ value={confirmarSenha}
162
+ onChangeText={(text) => setConfirmarSenha(text)}
163
+ />
164
+ <TouchableOpacity style={styles.button} onPress={handleCadastro}>
165
+ <Text style={styles.buttonText}>Cadastrar</Text>
166
+ </TouchableOpacity>
167
+ </View>
168
+ </Modal>
169
+ );
170
+ };
171
+
172
+ const styles = StyleSheet.create({
173
+ container: {
174
+ flex: 1,
175
+ alignItems: 'center',
176
+ justifyContent: 'center',
177
+ backgroundColor: '#fff',
178
+ },
179
+ title: {
180
+ fontSize: 24,
181
+ marginBottom: 16,
182
+ color: '#00bfff',
183
+ },
184
+ input: {
185
+ width: '80%',
186
+ height: 50,
187
+ padding: 10,
188
+ borderWidth: 1,
189
+ borderColor: '#ccc',
190
+ borderRadius: 4,
191
+ marginBottom: 16,
192
+ fontSize: 16,
193
+ color: '#000',
194
+ },
195
+ button: {
196
+ width: '80%',
197
+ height: 50,
198
+ backgroundColor: '#00bfff',
199
+ borderRadius: 4,
200
+ alignItems: 'center',
201
+ justifyContent: 'center',
202
+ },
203
+ buttonText: {
204
+ fontSize: 16,
205
+ color: '#fff',
206
+ },
207
+ logo: {
208
+ width: 500,
209
+ height: 250,
210
+ resizeMode: 'contain',
211
+ },
212
+ });
@@ -0,0 +1,308 @@
1
+ /* eslint-disable react-native/no-inline-styles */
2
+ import React, { useCallback, useEffect, useRef, useState } from 'react';
3
+ import { Text, View, TouchableOpacity, Button } from 'react-native';
4
+ import {
5
+ Camera,
6
+ useCameraDevice,
7
+ useCameraFormat,
8
+ type VideoFile,
9
+ } from 'react-native-vision-camera';
10
+ import Modal, { type ModalProps } from 'react-native-modal';
11
+ import { Toast } from '../../components/Toast/Toast';
12
+ import { provaVida } from '../../services';
13
+ import { getConfigCamera } from '../../utils';
14
+ import { Alert } from 'react-native';
15
+ import type { ScreenProps } from '../../types/screen';
16
+ import { Platform } from 'react-native';
17
+ import Orientation from 'react-native-orientation-locker';
18
+ import { WaitingForResult } from '../../components/WaitingForResult';
19
+ import { ErrorDisplay } from '../../components/ErrorDisplay';
20
+ import { DeviceNullDisplay } from '../../components/DeviceNullDisplay';
21
+ import { styles } from './styles';
22
+ import { CameraConfigInfos } from '../../components/CameraConfigInfos';
23
+
24
+ const IS_IOS = Platform.OS === 'ios';
25
+
26
+ interface CameraProvaVidasProps {
27
+ isVisible: boolean;
28
+ onCloseModal?: () => void;
29
+ onError?: (response?: any) => void;
30
+ onSuccess?: (response?: any) => void;
31
+ ModalParams?: ModalProps;
32
+ screenProps?: ScreenProps;
33
+ }
34
+
35
+ type GetConfigApi = {
36
+ id: number;
37
+ deviceModels: string[];
38
+ deviceType: string;
39
+ fps: number;
40
+ exposure: number;
41
+ zoom: number;
42
+ serviceType: string;
43
+ showButtonInfo: boolean;
44
+ };
45
+
46
+ export const CameraProvaVidas: React.FC<CameraProvaVidasProps> = ({
47
+ isVisible = false,
48
+ onCloseModal,
49
+ onError,
50
+ onSuccess,
51
+ ModalParams,
52
+ screenProps,
53
+ }) => {
54
+ const id = screenProps?.id;
55
+ const camera = useRef<Camera>(null);
56
+
57
+ const [showOverlay, setShowOverlay] = useState(false);
58
+ const [intervalState, setIntervalState] = useState<NodeJS.Timeout | null>(
59
+ null
60
+ );
61
+
62
+ const [timer, setTimer] = useState(0);
63
+ const [load, setLoad] = useState(false);
64
+ const [stateToastBpm, setStateToastBpm] = useState({
65
+ message: '',
66
+ visible: false,
67
+ });
68
+ const [isRecording, setIsRecording] = useState(false);
69
+ const [cameraConfigs, setCameraConfigs] = useState<GetConfigApi>();
70
+
71
+ // mantem a tela em modo portrait
72
+ useEffect(() => {
73
+ Orientation.lockToPortrait();
74
+ return () => {
75
+ Orientation.unlockAllOrientations();
76
+ };
77
+ }, []);
78
+
79
+ // Pega a permissão da camera do dispositivo
80
+ const requestCameraPermission = useCallback(async () => {
81
+ try {
82
+ await Camera.requestCameraPermission();
83
+ } catch (error) {}
84
+ }, []);
85
+
86
+ // pra garantir que a permissão da camera seja solicitada
87
+ useEffect(() => {
88
+ requestCameraPermission();
89
+ }, [requestCameraPermission]);
90
+
91
+ useEffect(() => {
92
+ getConfigCamera('liveness')
93
+ .then((config) => {
94
+ setCameraConfigs(config);
95
+ })
96
+ .catch((error) => {
97
+ console.error(error);
98
+ });
99
+ }, []);
100
+
101
+ const device = useCameraDevice('back', {
102
+ physicalDevices: ['wide-angle-camera'],
103
+ });
104
+
105
+ const cameraFormat = useCameraFormat(device, [
106
+ {
107
+ videoResolution: {
108
+ height: 1280,
109
+ width: 720,
110
+ },
111
+ },
112
+ ]);
113
+
114
+ // Envia o arquivo para a api
115
+ const sendFile = useCallback(
116
+ async (file: VideoFile) => {
117
+ setLoad(true);
118
+
119
+ if (!id)
120
+ return Alert.alert(
121
+ 'Erro ao enviar o arquivo ( id error ), tente novamente mais tarde'
122
+ );
123
+
124
+ let req = await provaVida(file, id, cameraConfigs?.exposure);
125
+
126
+ if (req.code === 0 && req.bpm >= 0) {
127
+ setShowOverlay(false);
128
+
129
+ const optionsToast = {
130
+ message: `Seu batimento esta em: ${req.bpm}.\n Prova de vida concluida !`,
131
+ visible: true,
132
+ };
133
+ setStateToastBpm(optionsToast);
134
+ onSuccess && onSuccess(req);
135
+ } else {
136
+ Alert.alert(req.message);
137
+ onError && onError(req);
138
+ }
139
+ setLoad(false);
140
+ setShowOverlay(false);
141
+ return;
142
+ },
143
+ [cameraConfigs?.exposure, id, onError, onSuccess]
144
+ );
145
+
146
+ // Limpa tudo
147
+ useEffect(() => {
148
+ return () => {
149
+ // limpa tudo
150
+ setTimer(0);
151
+ setIsRecording(false);
152
+ setLoad(false);
153
+ setStateToastBpm({ message: '', visible: false });
154
+ };
155
+ }, []);
156
+
157
+ // Limpa o intervalo do timer
158
+ useEffect(() => {
159
+ if (timer < 0) {
160
+ if (!intervalState) return;
161
+ clearInterval(intervalState);
162
+ stopRecodingVideo();
163
+ }
164
+ }, [timer, intervalState]);
165
+
166
+ // Função para iniciar a gravação do video na referencia da camera
167
+ const startVideoRecording = useCallback(() => {
168
+ setIsRecording(true);
169
+
170
+ camera.current?.startRecording({
171
+ fileType: 'mp4',
172
+ onRecordingFinished: (video) => sendFile(video),
173
+ onRecordingError: (error) => console.error(error),
174
+ });
175
+ }, [sendFile]);
176
+
177
+ // Inicia a gravação do video
178
+ const recordingVideo = useCallback(async () => {
179
+ startVideoRecording();
180
+ setTimer(10);
181
+ setLoad(true);
182
+
183
+ setIntervalState(
184
+ setInterval(() => {
185
+ setTimer((prevTimer) => prevTimer - 1); // Update the timer state
186
+ }, 1000)
187
+ );
188
+ }, [startVideoRecording]);
189
+
190
+ // Para a gravação do video
191
+ const stopRecodingVideo = async () => {
192
+ setIsRecording(false);
193
+ await camera.current?.stopRecording();
194
+ setShowOverlay(true);
195
+ return;
196
+ };
197
+
198
+ // Fecha o modal
199
+ const onCloseModalHandler = () => {
200
+ resetScreenStatesAndCamera();
201
+ onCloseModal && onCloseModal();
202
+ };
203
+
204
+ // Limpa os estados da tela e a camera
205
+ const resetScreenStatesAndCamera = () => {
206
+ setTimer(0);
207
+ setIsRecording(false);
208
+ setShowOverlay(false);
209
+ setLoad(false);
210
+ setStateToastBpm({ message: '', visible: false });
211
+ };
212
+
213
+ if (!screenProps && isVisible) {
214
+ return (
215
+ <ErrorDisplay
216
+ isVisible={isVisible}
217
+ modalParams={ModalParams}
218
+ onCloseModalHandler={onCloseModalHandler}
219
+ requestCameraPermission={requestCameraPermission}
220
+ />
221
+ );
222
+ }
223
+
224
+ if (device == null) {
225
+ return (
226
+ <DeviceNullDisplay
227
+ isVisible={isVisible}
228
+ modalParams={ModalParams}
229
+ onCloseModalHandler={onCloseModalHandler}
230
+ requestCameraPermission={requestCameraPermission}
231
+ />
232
+ );
233
+ }
234
+
235
+ return (
236
+ <Modal
237
+ style={{ margin: 0 }}
238
+ isVisible={isVisible}
239
+ swipeDirection="down"
240
+ propagateSwipe={true}
241
+ onSwipeComplete={onCloseModalHandler}
242
+ {...ModalParams}
243
+ >
244
+ <View style={styles.container}>
245
+ {showOverlay && (
246
+ <WaitingForResult
247
+ onPress={() => {
248
+ setShowOverlay(false);
249
+ }}
250
+ />
251
+ )}
252
+
253
+ <Toast
254
+ message={stateToastBpm.message}
255
+ isVisible={stateToastBpm.visible}
256
+ onClose={onCloseModalHandler}
257
+ />
258
+
259
+ <View style={styles.containerCamera}>
260
+ <Camera
261
+ ref={camera}
262
+ style={styles.subContainer}
263
+ isActive={true}
264
+ device={device}
265
+ video={true}
266
+ torch={'on'}
267
+ format={cameraFormat}
268
+ exposure={cameraConfigs?.exposure}
269
+ zoom={cameraConfigs?.zoom}
270
+ />
271
+ <View style={styles.cameraView} />
272
+ <View style={styles.containerTouch}>
273
+ <TouchableOpacity
274
+ onPress={() => recordingVideo()}
275
+ disabled={isRecording || load}
276
+ >
277
+ <View style={styles.containerText}>
278
+ <Text style={styles.textRecording}>
279
+ {isRecording
280
+ ? `Aguarde ${timer} segundos`
281
+ : load
282
+ ? 'Processando...'
283
+ : 'Medir Batimentos'}
284
+ </Text>
285
+ </View>
286
+ </TouchableOpacity>
287
+ </View>
288
+ <View
289
+ style={{
290
+ marginBottom: IS_IOS ? 48 : 0,
291
+ }}
292
+ >
293
+ <CameraConfigInfos
294
+ exposure={cameraConfigs?.exposure}
295
+ zoom={cameraConfigs?.zoom}
296
+ showButtonInfo={cameraConfigs?.showButtonInfo}
297
+ />
298
+ <Button
299
+ disabled={load}
300
+ title="Fechar Camera"
301
+ onPress={onCloseModalHandler}
302
+ />
303
+ </View>
304
+ </View>
305
+ </View>
306
+ </Modal>
307
+ );
308
+ };
@@ -0,0 +1,99 @@
1
+ import { StyleSheet } from 'react-native';
2
+ import { RFValue } from 'react-native-responsive-fontsize';
3
+
4
+ export const styles = StyleSheet.create({
5
+ container: {
6
+ flex: 1,
7
+ },
8
+
9
+ subContainer: {
10
+ flex: 1,
11
+ },
12
+
13
+ image: {
14
+ width: RFValue(200),
15
+ height: RFValue(200),
16
+ },
17
+
18
+ modalImage: {
19
+ width: '100%',
20
+ height: '100%',
21
+ resizeMode: 'contain',
22
+ },
23
+
24
+ overlay: {
25
+ zIndex: 2,
26
+ flex: 1,
27
+ height: '100%',
28
+ width: '100%',
29
+ backgroundColor: `rgba(44, 45, 46, 0.5)`,
30
+ alignItems: `center`,
31
+ justifyContent: `center`,
32
+ position: `absolute`,
33
+ },
34
+
35
+ textOverlay: {
36
+ fontSize: RFValue(18),
37
+ fontWeight: `500`,
38
+ color: `#fff`,
39
+ textAlign: `center`,
40
+ width: RFValue(300),
41
+ marginBottom: RFValue(20),
42
+ },
43
+
44
+ closeButton: {
45
+ position: 'absolute',
46
+ top: 20,
47
+ right: 20,
48
+ },
49
+
50
+ closeIcon: {
51
+ width: 20,
52
+ height: 20,
53
+ },
54
+
55
+ containerCamera: {
56
+ flex: 1,
57
+ },
58
+
59
+ cameraView: {
60
+ width: '100%',
61
+ height: RFValue(250),
62
+ backgroundColor: `rgba(173, 216, 230, 0)`,
63
+ position: `absolute`,
64
+ alignSelf: 'center',
65
+ marginTop: RFValue(50),
66
+ alignItems: `center`,
67
+ justifyContent: `center`,
68
+ },
69
+
70
+ containerTouch: {
71
+ height: RFValue(180),
72
+ alignItems: 'center',
73
+ },
74
+
75
+ containerText: {
76
+ width: RFValue(280),
77
+ height: RFValue(120),
78
+ borderRadius: 150,
79
+ backgroundColor: `blue`,
80
+ alignItems: `center`,
81
+ justifyContent: `center`,
82
+ marginTop: 10,
83
+ },
84
+
85
+ textRecording: {
86
+ fontSize: RFValue(18),
87
+ fontWeight: `500`,
88
+ color: `#fff`,
89
+ },
90
+ containerTextExposureAndZoom: {},
91
+ textExposureAndZoom: {
92
+ fontSize: 18,
93
+ fontWeight: `500`,
94
+ color: `#fff`,
95
+ textAlign: `center`,
96
+ width: RFValue(300),
97
+ marginBottom: RFValue(20),
98
+ },
99
+ });