@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 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: async (options = {}) => {
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, useState} from 'react';
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 EventThrottleMs = 500;
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 [lastEvent, setLastEvent] = useState<string | null>(null);
30
- const [lastEventTime, setLastEventTime] = useState<Date | null>(null);
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: any) => {
49
+ const capture = async (options = {}) => {
50
+ let data;
52
51
  try {
53
- const data = await cameraRef.current?.capture(options);
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 outdated = lastEventTime
63
- ? new Date().getTime() - lastEventTime.getTime() > EventThrottleMs
64
- : true;
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
- setLastEvent(value);
70
- setLastEventTime(new Date());
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}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/camerakit",
3
- "version": "0.89.1-beta.3",
3
+ "version": "0.89.1-beta.4",
4
4
  "private": false,
5
5
  "main": "index.tsx",
6
6
  "peerDependencies": {