@momo-kits/camerakit 0.89.1-beta.3 → 0.89.1-beta.4
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/Camera.ios.tsx +1 -3
- package/index.tsx +14 -16
- package/package.json +1 -1
package/Camera.ios.tsx
CHANGED
|
@@ -7,9 +7,7 @@ const NativeCamera = requireNativeComponent('CameraKit');
|
|
|
7
7
|
|
|
8
8
|
const Camera = React.forwardRef((props: any, ref: any) => {
|
|
9
9
|
React.useImperativeHandle<any, CameraApi>(ref, () => ({
|
|
10
|
-
capture:
|
|
11
|
-
return await CameraKitManager.capture(options);
|
|
12
|
-
},
|
|
10
|
+
capture: CameraKitManager.capture,
|
|
13
11
|
startCamera: CameraKitManager.startCamera,
|
|
14
12
|
stopCamera: CameraKitManager.stopCamera,
|
|
15
13
|
readImageQRCode: CameraKitManager.readImageQRCode,
|
package/index.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, {useRef
|
|
1
|
+
import React, {useRef} from 'react';
|
|
2
2
|
import {Platform, StyleSheet, View} from 'react-native';
|
|
3
3
|
import styles from './styles';
|
|
4
4
|
import CameraIOS from './Camera.ios';
|
|
@@ -7,7 +7,7 @@ import {CameraApi, CameraKitProps} from './type';
|
|
|
7
7
|
|
|
8
8
|
const Camera = Platform.OS == 'ios' ? CameraIOS : CameraAndroid;
|
|
9
9
|
|
|
10
|
-
const
|
|
10
|
+
const ThrottleEvent = 500;
|
|
11
11
|
|
|
12
12
|
const CameraKit = React.forwardRef(
|
|
13
13
|
(
|
|
@@ -17,8 +17,6 @@ const CameraKit = React.forwardRef(
|
|
|
17
17
|
onImageCaptured,
|
|
18
18
|
type = 'back',
|
|
19
19
|
torchMode = 'off',
|
|
20
|
-
zoomMode = 'off',
|
|
21
|
-
zoomRate = 1.0,
|
|
22
20
|
onOpenCamera = data => {},
|
|
23
21
|
customFinder,
|
|
24
22
|
style,
|
|
@@ -26,8 +24,8 @@ const CameraKit = React.forwardRef(
|
|
|
26
24
|
ref,
|
|
27
25
|
) => {
|
|
28
26
|
const cameraRef = useRef<any>(null);
|
|
29
|
-
const
|
|
30
|
-
const
|
|
27
|
+
const lastEvent = useRef<any>(null);
|
|
28
|
+
const lastTime = useRef<number>(0);
|
|
31
29
|
|
|
32
30
|
React.useImperativeHandle<any, CameraApi>(ref, () => ({
|
|
33
31
|
capture,
|
|
@@ -48,26 +46,27 @@ const CameraKit = React.forwardRef(
|
|
|
48
46
|
cameraRef.current?.stopCamera();
|
|
49
47
|
};
|
|
50
48
|
|
|
51
|
-
const capture = async (options
|
|
49
|
+
const capture = async (options = {}) => {
|
|
50
|
+
let data;
|
|
52
51
|
try {
|
|
53
|
-
|
|
52
|
+
data = await cameraRef.current?.capture(options);
|
|
54
53
|
onImageCaptured?.({...data, url: data.uri});
|
|
55
54
|
} catch (e: any) {
|
|
56
55
|
onImageCaptured?.({error: e.message});
|
|
57
56
|
}
|
|
57
|
+
return data;
|
|
58
58
|
};
|
|
59
59
|
|
|
60
60
|
const onBarCodeReadHandler = ({nativeEvent}: any) => {
|
|
61
61
|
const value = JSON.stringify(nativeEvent);
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (value && value === lastEvent && !outdated) {
|
|
62
|
+
const now = Date.now();
|
|
63
|
+
const outdated = !lastTime || now - lastTime.current > ThrottleEvent;
|
|
64
|
+
if (value && value === lastEvent.current && !outdated) {
|
|
66
65
|
return;
|
|
67
66
|
}
|
|
68
67
|
onBarCodeRead?.({data: nativeEvent?.codeStringValue});
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
lastEvent.current = value;
|
|
69
|
+
lastTime.current = Date.now();
|
|
71
70
|
};
|
|
72
71
|
|
|
73
72
|
const onMRZHandler = ({nativeEvent}: any) => {
|
|
@@ -86,9 +85,8 @@ const CameraKit = React.forwardRef(
|
|
|
86
85
|
cameraType={type}
|
|
87
86
|
torchMode={torchMode}
|
|
88
87
|
focusMode={torchMode}
|
|
89
|
-
zoomMode={zoomMode}
|
|
90
|
-
zoomRate={zoomRate}
|
|
91
88
|
scanBarcode={!!onBarCodeRead}
|
|
89
|
+
scanMRZ={!!onMRZ}
|
|
92
90
|
onReadCode={onBarCodeReadHandler}
|
|
93
91
|
onMRZ={onMRZHandler}
|
|
94
92
|
onOpenCamera={onOpenCameraHandler}
|