react-native-biometric-verifier 0.0.37 → 0.0.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.js +48 -54
- package/src/hooks/useImageProcessing.js +0 -64
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
TouchableOpacity,
|
|
11
11
|
Text,
|
|
12
12
|
Modal,
|
|
13
|
-
InteractionManager,
|
|
14
13
|
StyleSheet,
|
|
15
14
|
Platform,
|
|
16
15
|
Animated,
|
|
@@ -21,7 +20,6 @@ import { useNavigation } from "@react-navigation/native";
|
|
|
21
20
|
// Custom hooks
|
|
22
21
|
import { useCountdown } from "./hooks/useCountdown";
|
|
23
22
|
import { useGeolocation } from "./hooks/useGeolocation";
|
|
24
|
-
import { useImageProcessing } from "./hooks/useImageProcessing";
|
|
25
23
|
import { useNotifyMessage } from "./hooks/useNotifyMessage";
|
|
26
24
|
import { useSafeCallback } from "./hooks/useSafeCallback";
|
|
27
25
|
|
|
@@ -46,7 +44,6 @@ const BiometricModal = React.memo(
|
|
|
46
44
|
// Custom hooks
|
|
47
45
|
const { countdown, startCountdown, resetCountdown, pauseCountdown, resumeCountdown } = useCountdown();
|
|
48
46
|
const { requestLocationPermission, getCurrentLocation } = useGeolocation();
|
|
49
|
-
const { convertImageToBase64 } = useImageProcessing();
|
|
50
47
|
const { notification, fadeAnim, slideAnim, notifyMessage, clearNotification } = useNotifyMessage();
|
|
51
48
|
const safeCallback = useSafeCallback(callback, notifyMessage);
|
|
52
49
|
|
|
@@ -231,71 +228,68 @@ const BiometricModal = React.memo(
|
|
|
231
228
|
animationState: Global.AnimationStates.processing,
|
|
232
229
|
});
|
|
233
230
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
231
|
+
if (!base64) {
|
|
232
|
+
handleProcessError("Failed to process image.");
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
239
235
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
236
|
+
try {
|
|
237
|
+
const body = { image: base64 };
|
|
238
|
+
const header = { faceid: currentData };
|
|
239
|
+
const buttonapi = `${apiurl}python/recognize`;
|
|
240
|
+
|
|
241
|
+
updateState({
|
|
242
|
+
loadingType: Global.LoadingTypes.networkRequest,
|
|
243
|
+
});
|
|
244
|
+
console.log("API URL:", buttonapi);
|
|
245
|
+
console.log("Sending request to API...", JSON.stringify(body));
|
|
246
|
+
const response = await networkServiceCall(
|
|
247
|
+
"POST",
|
|
248
|
+
buttonapi,
|
|
249
|
+
header,
|
|
250
|
+
body
|
|
251
|
+
);
|
|
252
|
+
console.log("API Response:", JSON.stringify(response));
|
|
253
|
+
if (response?.httpstatus === 200 && response?.data?.data) {
|
|
254
|
+
responseRef.current = response;
|
|
244
255
|
|
|
245
256
|
updateState({
|
|
246
|
-
|
|
257
|
+
employeeData: response.data?.data || null,
|
|
258
|
+
animationState: Global.AnimationStates.success,
|
|
259
|
+
isLoading: false,
|
|
260
|
+
loadingType: Global.LoadingTypes.none,
|
|
247
261
|
});
|
|
248
|
-
console.log("API URL:", buttonapi);
|
|
249
|
-
console.log("Sending request to API...", JSON.stringify(body));
|
|
250
|
-
const response = await networkServiceCall(
|
|
251
|
-
"POST",
|
|
252
|
-
buttonapi,
|
|
253
|
-
header,
|
|
254
|
-
body
|
|
255
|
-
);
|
|
256
|
-
console.log("API Response:", JSON.stringify(response));
|
|
257
|
-
if (response?.httpstatus === 200 && response?.data?.data) {
|
|
258
|
-
responseRef.current = response;
|
|
259
262
|
|
|
260
|
-
|
|
261
|
-
employeeData: response.data?.data || null,
|
|
262
|
-
animationState: Global.AnimationStates.success,
|
|
263
|
-
isLoading: false,
|
|
264
|
-
loadingType: Global.LoadingTypes.none,
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
notifyMessage("Identity verified successfully!", "success");
|
|
268
|
-
|
|
269
|
-
if (qrscan) {
|
|
270
|
-
setTimeout(() => startQRCodeScan(), 1200);
|
|
271
|
-
} else {
|
|
272
|
-
safeCallback(responseRef.current);
|
|
263
|
+
notifyMessage("Identity verified successfully!", "success");
|
|
273
264
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
265
|
+
if (qrscan) {
|
|
266
|
+
setTimeout(() => startQRCodeScan(), 1200);
|
|
267
|
+
} else {
|
|
268
|
+
safeCallback(responseRef.current);
|
|
277
269
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
}, 1200);
|
|
270
|
+
if (resetTimeoutRef.current) {
|
|
271
|
+
clearTimeout(resetTimeoutRef.current);
|
|
281
272
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
);
|
|
273
|
+
|
|
274
|
+
resetTimeoutRef.current = setTimeout(() => {
|
|
275
|
+
resetState();
|
|
276
|
+
}, 1200);
|
|
287
277
|
}
|
|
288
|
-
}
|
|
289
|
-
console.error("Network request failed:", error);
|
|
278
|
+
} else {
|
|
290
279
|
handleProcessError(
|
|
291
|
-
|
|
292
|
-
|
|
280
|
+
response?.data?.message ||
|
|
281
|
+
"Face not recognized. Please try again."
|
|
293
282
|
);
|
|
294
283
|
}
|
|
295
|
-
})
|
|
284
|
+
} catch (error) {
|
|
285
|
+
console.error("Network request failed:", error);
|
|
286
|
+
handleProcessError(
|
|
287
|
+
"Connection error. Please check your network.",
|
|
288
|
+
error
|
|
289
|
+
);
|
|
290
|
+
}
|
|
296
291
|
},
|
|
297
292
|
[
|
|
298
|
-
convertImageToBase64,
|
|
299
293
|
notifyMessage,
|
|
300
294
|
qrscan,
|
|
301
295
|
resetState,
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { useCallback } from 'react';
|
|
2
|
-
import ImageResizer from 'react-native-image-resizer';
|
|
3
|
-
import RNFS from 'react-native-fs';
|
|
4
|
-
import { Global } from '../utils/Global';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Custom hook to process images: resize and convert to Base64.
|
|
8
|
-
*
|
|
9
|
-
* @returns {Object} { convertImageToBase64 }
|
|
10
|
-
*/
|
|
11
|
-
export const useImageProcessing = () => {
|
|
12
|
-
/**
|
|
13
|
-
* Converts an image URI to a Base64 string after resizing.
|
|
14
|
-
*
|
|
15
|
-
* @param {string} uri - Image file URI.
|
|
16
|
-
* @param {boolean} includeMimeType - Whether to include MIME type in the result.
|
|
17
|
-
* @returns {Promise<string>} Base64 string of the image.
|
|
18
|
-
*/
|
|
19
|
-
const convertImageToBase64 = useCallback(async (uri, includeMimeType = false) => {
|
|
20
|
-
try {
|
|
21
|
-
if (!uri || typeof uri !== 'string') {
|
|
22
|
-
throw new Error('Invalid image URI provided.');
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Optional: Check file info
|
|
26
|
-
try {
|
|
27
|
-
await RNFS.stat(uri);
|
|
28
|
-
} catch {
|
|
29
|
-
// Skip warnings; silently ignore
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Resize image
|
|
33
|
-
const resizedImage = await ImageResizer.createResizedImage(
|
|
34
|
-
uri,
|
|
35
|
-
Global.ImageResize.width,
|
|
36
|
-
Global.ImageResize.height,
|
|
37
|
-
Global.ImageResize.format, // 'JPEG' or 'PNG'
|
|
38
|
-
Global.ImageResize.quality, // e.g., 80
|
|
39
|
-
0, // Rotation
|
|
40
|
-
undefined, // Output path
|
|
41
|
-
false // Keep EXIF metadata
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
if (!resizedImage?.uri) {
|
|
45
|
-
throw new Error('Image resizing returned an invalid result.');
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Convert resized image to Base64
|
|
49
|
-
let base64Data = await RNFS.readFile(resizedImage.uri, 'base64');
|
|
50
|
-
|
|
51
|
-
if (includeMimeType) {
|
|
52
|
-
const mimeType = Global.ImageResize.format.toLowerCase() === 'png' ? 'image/png' : 'image/jpeg';
|
|
53
|
-
base64Data = `data:${mimeType};base64,${base64Data}`;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return base64Data;
|
|
57
|
-
} catch (error) {
|
|
58
|
-
console.error('Error in convertImageToBase64:', error.message || error);
|
|
59
|
-
throw error; // Rethrow for caller handling
|
|
60
|
-
}
|
|
61
|
-
}, []);
|
|
62
|
-
|
|
63
|
-
return { convertImageToBase64 };
|
|
64
|
-
};
|