@momo-kits/camerakit 0.0.51-beta.2
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/CameraKit.js +105 -0
- package/index.js +3 -0
- package/package.json +15 -0
- package/publish.sh +28 -0
package/CameraKit.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { StyleSheet, View } from 'react-native';
|
|
4
|
+
import { Camera } from 'react-native-camera-kit';
|
|
5
|
+
|
|
6
|
+
const styles = StyleSheet.create({
|
|
7
|
+
container: {
|
|
8
|
+
overflow: 'hidden',
|
|
9
|
+
},
|
|
10
|
+
camera: {
|
|
11
|
+
flex: 1,
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const EventThrottleMs = 250;
|
|
16
|
+
|
|
17
|
+
class CameraKit extends React.Component {
|
|
18
|
+
constructor(props) {
|
|
19
|
+
super(props);
|
|
20
|
+
this.camera = null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
readImageQRCode = (base64) => {
|
|
24
|
+
this.camera?.readImageQRCode(base64);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
startCamera = () => {
|
|
28
|
+
this.camera?.startCamera();
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
stopCamera = () => {
|
|
32
|
+
this.camera?.stopCamera();
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
async capture(options) {
|
|
36
|
+
const data = await this.camera?.capture(options);
|
|
37
|
+
const { onImageCaptured } = this.props;
|
|
38
|
+
if (typeof onImageCaptured === 'function') {
|
|
39
|
+
onImageCaptured({ ...data, url: data.uri });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
onBarCodeRead = ({ nativeEvent }) => {
|
|
44
|
+
const value = JSON.stringify(nativeEvent);
|
|
45
|
+
const outdated = new Date() - this.lastEventTime > EventThrottleMs;
|
|
46
|
+
if (value && value === this.lastEvent && !outdated) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const { onBarCodeRead } = this.props;
|
|
50
|
+
if (typeof onBarCodeRead === 'function') {
|
|
51
|
+
onBarCodeRead({ data: nativeEvent?.codeStringValue });
|
|
52
|
+
this.lastEvent = value;
|
|
53
|
+
this.lastEventTime = new Date();
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
render() {
|
|
58
|
+
const {
|
|
59
|
+
customFinder,
|
|
60
|
+
style,
|
|
61
|
+
torchMode,
|
|
62
|
+
type,
|
|
63
|
+
onBarCodeRead,
|
|
64
|
+
onOpenCamera,
|
|
65
|
+
zoomMode,
|
|
66
|
+
} = this.props;
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<View style={[styles.container, style]}>
|
|
70
|
+
<Camera
|
|
71
|
+
ref={(cam) => (this.camera = cam)}
|
|
72
|
+
style={styles.camera}
|
|
73
|
+
cameraType={type}
|
|
74
|
+
torchMode={torchMode}
|
|
75
|
+
focusMode={torchMode}
|
|
76
|
+
zoomMode={zoomMode}
|
|
77
|
+
scanBarcode={!!onBarCodeRead}
|
|
78
|
+
onReadCode={this.onBarCodeRead}
|
|
79
|
+
onOpenCamera={onOpenCamera}
|
|
80
|
+
/>
|
|
81
|
+
<View style={StyleSheet.absoluteFill}>
|
|
82
|
+
{customFinder && customFinder()}
|
|
83
|
+
</View>
|
|
84
|
+
</View>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
CameraKit.propTypes = {
|
|
90
|
+
onBarCodeRead: PropTypes.func,
|
|
91
|
+
onImageCaptured: PropTypes.func,
|
|
92
|
+
type: PropTypes.oneOf(['front', 'back']),
|
|
93
|
+
torchMode: PropTypes.oneOf(['on', 'off', 'auto']),
|
|
94
|
+
zoomMode: PropTypes.oneOf(['on', 'off']),
|
|
95
|
+
onOpenCamera: PropTypes.func,
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
CameraKit.defaultProps = {
|
|
99
|
+
type: 'back',
|
|
100
|
+
torchMode: 'off',
|
|
101
|
+
zoomMode: 'off',
|
|
102
|
+
onOpenCamera: () => {},
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export default CameraKit;
|
package/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@momo-kits/camerakit",
|
|
3
|
+
"version": "0.0.51-beta.2",
|
|
4
|
+
"private": false,
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"@momo-platform/versions": "4.0.2"
|
|
8
|
+
},
|
|
9
|
+
"peerDependencies": {
|
|
10
|
+
"react": "16.9.0",
|
|
11
|
+
"react-native": ">=0.55"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {},
|
|
14
|
+
"license": "MoMo"
|
|
15
|
+
}
|
package/publish.sh
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
rm -rf dist
|
|
3
|
+
mkdir dist
|
|
4
|
+
|
|
5
|
+
cp . ./dist
|
|
6
|
+
|
|
7
|
+
# GET VERSION from mck_package.json
|
|
8
|
+
VERSIONSTRING=( v$(jq .version package.json) )
|
|
9
|
+
VERSION=(${VERSIONSTRING//[\"]/})
|
|
10
|
+
echo VERSION: $VERSION
|
|
11
|
+
|
|
12
|
+
rsync -r --verbose --exclude '*.mdx' --exclude '*Demo.js' --exclude 'props-type.js' --exclude 'prop-types.js' ./* dist
|
|
13
|
+
|
|
14
|
+
# #babel component to dist
|
|
15
|
+
#babel ./dist -d dist --copy-files
|
|
16
|
+
|
|
17
|
+
#copy option
|
|
18
|
+
#cp -r ./src/ dist
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
#npm login
|
|
22
|
+
#publish dist to npm
|
|
23
|
+
cd dist
|
|
24
|
+
npm publish --tag beta --access=public
|
|
25
|
+
cd ..
|
|
26
|
+
rm -rf dist
|
|
27
|
+
|
|
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/camerakit new version release: '*"$VERSION"*' https://www.npmjs.com/package/@momo-kits/camerakit"}'
|