@momo-kits/camerakit 0.0.65-beta.4 → 0.0.65-beta.40
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 +87 -83
- package/package.json +1 -1
package/CameraKit.js
CHANGED
|
@@ -1,110 +1,114 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import {StyleSheet, View} from 'react-native';
|
|
4
|
+
import {Camera} from 'camerakit';
|
|
5
5
|
|
|
6
6
|
const styles = StyleSheet.create({
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
container: {
|
|
8
|
+
overflow: 'hidden',
|
|
9
|
+
},
|
|
10
|
+
camera: {
|
|
11
|
+
flex: 1,
|
|
12
|
+
backgroundColor: 'black',
|
|
13
|
+
},
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
const EventThrottleMs = 250;
|
|
17
17
|
|
|
18
18
|
class CameraKit extends React.Component {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
constructor(props) {
|
|
20
|
+
super(props);
|
|
21
|
+
this.camera = null;
|
|
22
|
+
}
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
readImageQRCode = base64 => {
|
|
25
|
+
this.camera?.readImageQRCode(base64);
|
|
26
|
+
};
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
startCamera = () => {
|
|
29
|
+
this.camera?.startCamera();
|
|
30
|
+
};
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
stopCamera = () => {
|
|
33
|
+
this.camera?.stopCamera();
|
|
34
|
+
};
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
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});
|
|
44
43
|
}
|
|
44
|
+
}
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
onOpenCamera = ({nativeEvent}) => {
|
|
59
|
+
const {onOpenCamera} = this.props;
|
|
60
|
+
onOpenCamera?.(nativeEvent);
|
|
61
|
+
};
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
63
|
+
render() {
|
|
64
|
+
const {
|
|
65
|
+
customFinder,
|
|
66
|
+
style,
|
|
67
|
+
torchMode,
|
|
68
|
+
type,
|
|
69
|
+
onBarCodeRead,
|
|
70
|
+
zoomMode,
|
|
71
|
+
zoomRate,
|
|
72
|
+
} = this.props;
|
|
72
73
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
+
}
|
|
92
94
|
}
|
|
93
95
|
|
|
94
96
|
CameraKit.propTypes = {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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,
|
|
101
104
|
};
|
|
102
105
|
|
|
103
106
|
CameraKit.defaultProps = {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
107
|
+
type: 'back',
|
|
108
|
+
torchMode: 'off',
|
|
109
|
+
zoomMode: 'off',
|
|
110
|
+
zoomRate: 1.0,
|
|
111
|
+
onOpenCamera: () => {},
|
|
108
112
|
};
|
|
109
113
|
|
|
110
114
|
export default CameraKit;
|