@momo-kits/camerakit 0.73.3-beta.4 → 0.74.2-react-native.1
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.android.tsx +52 -0
- package/Camera.ios.tsx +33 -0
- package/index.tsx +96 -0
- package/package.json +10 -9
- package/publish.sh +1 -7
- package/styles.ts +12 -0
- package/type.ts +23 -0
- package/CameraKit.js +0 -114
- package/index.js +0 -3
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
findNodeHandle,
|
|
5
|
+
NativeModules,
|
|
6
|
+
requireNativeComponent,
|
|
7
|
+
} from 'react-native';
|
|
8
|
+
import {CameraApi} from './type';
|
|
9
|
+
|
|
10
|
+
let Module: any;
|
|
11
|
+
let NativeCamera: any;
|
|
12
|
+
|
|
13
|
+
if (NativeModules?.RNCameraKitModule) {
|
|
14
|
+
Module = NativeModules.RNCameraKitModule;
|
|
15
|
+
NativeCamera = requireNativeComponent('RNCameraManager');
|
|
16
|
+
} else {
|
|
17
|
+
Module = NativeModules.CameraKitModule;
|
|
18
|
+
NativeCamera = requireNativeComponent('CKCameraManager');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const Camera = React.forwardRef((props: any, ref) => {
|
|
22
|
+
const nativeRef = React.useRef();
|
|
23
|
+
|
|
24
|
+
React.useImperativeHandle<any, CameraApi>(ref, () => ({
|
|
25
|
+
capture: async (options = {}) => {
|
|
26
|
+
return await Module.capture(
|
|
27
|
+
options,
|
|
28
|
+
findNodeHandle(nativeRef.current ?? null),
|
|
29
|
+
);
|
|
30
|
+
},
|
|
31
|
+
startCamera: () => {
|
|
32
|
+
Module.startCamera(findNodeHandle(nativeRef.current ?? null));
|
|
33
|
+
},
|
|
34
|
+
stopCamera: () => {
|
|
35
|
+
Module.stopCamera(findNodeHandle(nativeRef.current ?? null));
|
|
36
|
+
},
|
|
37
|
+
readImageQRCode: (base64: string) => {
|
|
38
|
+
Module.readImageQRCode(base64, findNodeHandle(nativeRef.current ?? null));
|
|
39
|
+
},
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<NativeCamera
|
|
44
|
+
style={{minWidth: 100, minHeight: 100}}
|
|
45
|
+
ref={nativeRef}
|
|
46
|
+
onOpenCamera={(event: any) => {}}
|
|
47
|
+
{...props}
|
|
48
|
+
/>
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
export default Camera;
|
package/Camera.ios.tsx
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {NativeModules, requireNativeComponent} from 'react-native';
|
|
3
|
+
import {CameraApi} from './type';
|
|
4
|
+
|
|
5
|
+
let Module: any;
|
|
6
|
+
let NativeCamera: any;
|
|
7
|
+
|
|
8
|
+
if (NativeModules?.RNCameraKitManager) {
|
|
9
|
+
Module = NativeModules.RNCameraKitManager;
|
|
10
|
+
NativeCamera = requireNativeComponent('RNCameraKit');
|
|
11
|
+
} else {
|
|
12
|
+
Module = NativeModules.CameraKitManager;
|
|
13
|
+
NativeCamera = requireNativeComponent('CameraKit');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const Camera = React.forwardRef((props: any, ref: any) => {
|
|
17
|
+
React.useImperativeHandle<any, CameraApi>(ref, () => ({
|
|
18
|
+
capture: Module.capture,
|
|
19
|
+
startCamera: Module.startCamera,
|
|
20
|
+
stopCamera: Module.stopCamera,
|
|
21
|
+
readImageQRCode: Module.readImageQRCode,
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<NativeCamera
|
|
26
|
+
style={{minWidth: 100, minHeight: 100}}
|
|
27
|
+
onOpenCamera={(event: any) => {}}
|
|
28
|
+
{...props}
|
|
29
|
+
/>
|
|
30
|
+
);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export default Camera;
|
package/index.tsx
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import React, {useRef} from 'react';
|
|
2
|
+
import {Platform, StyleSheet, View} from 'react-native';
|
|
3
|
+
import styles from './styles';
|
|
4
|
+
import CameraIOS from './Camera.ios';
|
|
5
|
+
import CameraAndroid from './Camera.android';
|
|
6
|
+
import {CameraApi, CameraKitProps} from './type';
|
|
7
|
+
|
|
8
|
+
const Camera = Platform.OS == 'ios' ? CameraIOS : CameraAndroid;
|
|
9
|
+
|
|
10
|
+
const ThrottleEvent = 500;
|
|
11
|
+
|
|
12
|
+
const CameraKit = React.forwardRef(
|
|
13
|
+
(
|
|
14
|
+
{
|
|
15
|
+
onBarCodeRead,
|
|
16
|
+
onMRZ,
|
|
17
|
+
onImageCaptured,
|
|
18
|
+
type = 'back',
|
|
19
|
+
torchMode = 'off',
|
|
20
|
+
customFinder,
|
|
21
|
+
style,
|
|
22
|
+
}: CameraKitProps,
|
|
23
|
+
ref,
|
|
24
|
+
) => {
|
|
25
|
+
const cameraRef = useRef<any>(null);
|
|
26
|
+
const lastEvent = useRef<any>(null);
|
|
27
|
+
const lastTime = useRef<number>(0);
|
|
28
|
+
|
|
29
|
+
React.useImperativeHandle<any, CameraApi>(ref, () => ({
|
|
30
|
+
capture,
|
|
31
|
+
startCamera,
|
|
32
|
+
stopCamera,
|
|
33
|
+
readImageQRCode,
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
const readImageQRCode = (base64: string) => {
|
|
37
|
+
cameraRef.current?.readImageQRCode(base64);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const startCamera = () => {
|
|
41
|
+
cameraRef.current?.startCamera();
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const stopCamera = () => {
|
|
45
|
+
cameraRef.current?.stopCamera();
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const capture = async (options = {}) => {
|
|
49
|
+
let data;
|
|
50
|
+
try {
|
|
51
|
+
data = await cameraRef.current?.capture(options);
|
|
52
|
+
onImageCaptured?.({...data, url: data.uri});
|
|
53
|
+
} catch (e: any) {
|
|
54
|
+
onImageCaptured?.({error: e.message});
|
|
55
|
+
}
|
|
56
|
+
return data;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const onBarCodeReadHandler = ({nativeEvent}: any) => {
|
|
60
|
+
const value = JSON.stringify(nativeEvent);
|
|
61
|
+
const now = Date.now();
|
|
62
|
+
const outdated = !lastTime || now - lastTime.current > ThrottleEvent;
|
|
63
|
+
if (value && value === lastEvent.current && !outdated) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
onBarCodeRead?.({data: nativeEvent?.codeStringValue});
|
|
67
|
+
lastEvent.current = value;
|
|
68
|
+
lastTime.current = Date.now();
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const onMRZHandler = ({nativeEvent}: any) => {
|
|
72
|
+
onMRZ?.({data: nativeEvent?.docMRZ});
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<View style={[styles.container, style]}>
|
|
77
|
+
<Camera
|
|
78
|
+
ref={cameraRef}
|
|
79
|
+
style={styles.camera}
|
|
80
|
+
cameraType={type}
|
|
81
|
+
torchMode={torchMode}
|
|
82
|
+
focusMode={torchMode}
|
|
83
|
+
scanBarcode={!!onBarCodeRead}
|
|
84
|
+
scanMRZ={!!onMRZ}
|
|
85
|
+
onReadCode={onBarCodeReadHandler}
|
|
86
|
+
onMRZ={onMRZHandler}
|
|
87
|
+
/>
|
|
88
|
+
{customFinder && (
|
|
89
|
+
<View style={StyleSheet.absoluteFill}>{customFinder()}</View>
|
|
90
|
+
)}
|
|
91
|
+
</View>
|
|
92
|
+
);
|
|
93
|
+
},
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
export {CameraKit};
|
package/package.json
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@momo-kits/camerakit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.74.2-react-native.1",
|
|
4
4
|
"private": false,
|
|
5
|
-
"main": "index.
|
|
6
|
-
"dependencies": {
|
|
7
|
-
"camerakit": "git+https://gitlab.mservice.com.vn/momo-platform/react-native-camera-kit.git#v2.0.5"
|
|
8
|
-
},
|
|
5
|
+
"main": "index.tsx",
|
|
9
6
|
"peerDependencies": {
|
|
10
|
-
"react": "
|
|
11
|
-
"react-native": "
|
|
7
|
+
"react": "*",
|
|
8
|
+
"react-native": "*",
|
|
9
|
+
"prop-types": "15.7.2"
|
|
10
|
+
},
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"@momo-platform/versions": "4.1.11"
|
|
12
13
|
},
|
|
13
|
-
"
|
|
14
|
-
"
|
|
14
|
+
"license": "MoMo",
|
|
15
|
+
"dependencies": {}
|
|
15
16
|
}
|
package/publish.sh
CHANGED
|
@@ -11,12 +11,6 @@ echo VERSION: $VERSION
|
|
|
11
11
|
|
|
12
12
|
rsync -r --verbose --exclude '*.mdx' --exclude '*Demo.js' --exclude 'props-type.js' --exclude 'prop-types.js' ./* dist
|
|
13
13
|
|
|
14
|
-
# #babel component to dist
|
|
15
|
-
#babel ./dist -d dist --copy-files
|
|
16
|
-
|
|
17
|
-
#copy option
|
|
18
|
-
#cp -r ./src/ dist
|
|
19
|
-
|
|
20
14
|
|
|
21
15
|
#npm login
|
|
22
16
|
#publish dist to npm
|
|
@@ -25,4 +19,4 @@ npm publish --tag beta --access=public
|
|
|
25
19
|
cd ..
|
|
26
20
|
rm -rf dist
|
|
27
21
|
|
|
28
|
-
##curl -X POST -H 'Content-Type: application/json' 'https://chat.googleapis.com/v1/spaces/AAAAbP8987c/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=UGSFRvk_oYb9uGsAgs31bVvMm6jDkmD8zihGm3eyaQA%3D&threadKey=JoaXTEYaNNkl' -d '{"text": "@momo-kits/
|
|
22
|
+
##curl -X POST -H 'Content-Type: application/json' 'https://chat.googleapis.com/v1/spaces/AAAAbP8987c/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=UGSFRvk_oYb9uGsAgs31bVvMm6jDkmD8zihGm3eyaQA%3D&threadKey=JoaXTEYaNNkl' -d '{"text": "@momo-kits/bank new version release: '*"$VERSION"*' `https://www.npmjs.com/package/@momo-kits/avatar`"}'
|
package/styles.ts
ADDED
package/type.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
export interface CameraKitProps {
|
|
4
|
+
onBarCodeRead?: (data: any) => void;
|
|
5
|
+
onMRZ?: (data: any) => void;
|
|
6
|
+
onImageCaptured?: (data: any) => void;
|
|
7
|
+
type?: 'front' | 'back';
|
|
8
|
+
torchMode?: 'on' | 'off' | 'auto';
|
|
9
|
+
zoomMode?: 'on' | 'off';
|
|
10
|
+
zoomRate?: number;
|
|
11
|
+
onOpenCamera?: (event: any) => void;
|
|
12
|
+
customFinder?: () => React.ReactNode;
|
|
13
|
+
style?: any;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type CameraApi = {
|
|
17
|
+
capture: (option: any) => Promise<any>;
|
|
18
|
+
stopCamera: () => void;
|
|
19
|
+
startCamera: () => void;
|
|
20
|
+
readImageQRCode: (base64: string) => void;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type CameraType = 'font' | 'back';
|
package/CameraKit.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import {StyleSheet, View} from 'react-native';
|
|
4
|
-
import {Camera} from 'camerakit';
|
|
5
|
-
|
|
6
|
-
const styles = StyleSheet.create({
|
|
7
|
-
container: {
|
|
8
|
-
overflow: 'hidden',
|
|
9
|
-
},
|
|
10
|
-
camera: {
|
|
11
|
-
flex: 1,
|
|
12
|
-
backgroundColor: 'black',
|
|
13
|
-
},
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
const EventThrottleMs = 250;
|
|
17
|
-
|
|
18
|
-
class CameraKit extends React.Component {
|
|
19
|
-
constructor(props) {
|
|
20
|
-
super(props);
|
|
21
|
-
this.camera = null;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
readImageQRCode = base64 => {
|
|
25
|
-
this.camera?.readImageQRCode(base64);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
startCamera = () => {
|
|
29
|
-
this.camera?.startCamera();
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
stopCamera = () => {
|
|
33
|
-
this.camera?.stopCamera();
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
async capture(options) {
|
|
37
|
-
const {onImageCaptured} = this.props;
|
|
38
|
-
try {
|
|
39
|
-
const data = await this.camera?.capture(options);
|
|
40
|
-
onImageCaptured?.({...data, url: data.uri});
|
|
41
|
-
} catch (e) {
|
|
42
|
-
onImageCaptured?.({error: e.message});
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
onBarCodeRead = ({nativeEvent}) => {
|
|
47
|
-
const value = JSON.stringify(nativeEvent);
|
|
48
|
-
const outdated = new Date() - this.lastEventTime > EventThrottleMs;
|
|
49
|
-
if (value && value === this.lastEvent && !outdated) {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
const {onBarCodeRead} = this.props;
|
|
53
|
-
onBarCodeRead?.({data: nativeEvent?.codeStringValue});
|
|
54
|
-
this.lastEvent = value;
|
|
55
|
-
this.lastEventTime = new Date();
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
onOpenCamera = ({nativeEvent}) => {
|
|
59
|
-
const {onOpenCamera} = this.props;
|
|
60
|
-
onOpenCamera?.(nativeEvent);
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
render() {
|
|
64
|
-
const {
|
|
65
|
-
customFinder,
|
|
66
|
-
style,
|
|
67
|
-
torchMode,
|
|
68
|
-
type,
|
|
69
|
-
onBarCodeRead,
|
|
70
|
-
zoomMode,
|
|
71
|
-
zoomRate,
|
|
72
|
-
} = this.props;
|
|
73
|
-
|
|
74
|
-
return (
|
|
75
|
-
<View style={[styles.container, style]}>
|
|
76
|
-
<Camera
|
|
77
|
-
ref={cam => (this.camera = cam)}
|
|
78
|
-
style={styles.camera}
|
|
79
|
-
cameraType={type}
|
|
80
|
-
torchMode={torchMode}
|
|
81
|
-
focusMode={torchMode}
|
|
82
|
-
zoomMode={zoomMode}
|
|
83
|
-
zoomRate={zoomRate}
|
|
84
|
-
scanBarcode={!!onBarCodeRead}
|
|
85
|
-
onReadCode={this.onBarCodeRead}
|
|
86
|
-
onOpenCamera={this.onOpenCamera}
|
|
87
|
-
/>
|
|
88
|
-
{customFinder && (
|
|
89
|
-
<View style={StyleSheet.absoluteFill}>{customFinder()}</View>
|
|
90
|
-
)}
|
|
91
|
-
</View>
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
CameraKit.propTypes = {
|
|
97
|
-
onBarCodeRead: PropTypes.func,
|
|
98
|
-
onImageCaptured: PropTypes.func,
|
|
99
|
-
type: PropTypes.oneOf(['front', 'back']),
|
|
100
|
-
torchMode: PropTypes.oneOf(['on', 'off', 'auto']),
|
|
101
|
-
zoomMode: PropTypes.oneOf(['on', 'off']),
|
|
102
|
-
zoomRate: PropTypes.number,
|
|
103
|
-
onOpenCamera: PropTypes.func,
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
CameraKit.defaultProps = {
|
|
107
|
-
type: 'back',
|
|
108
|
-
torchMode: 'off',
|
|
109
|
-
zoomMode: 'off',
|
|
110
|
-
zoomRate: 1.0,
|
|
111
|
-
onOpenCamera: () => {},
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
export default CameraKit;
|
package/index.js
DELETED