@momo-kits/camerakit 0.0.65-beta.30 → 0.0.65-beta.31

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.
Files changed (2) hide show
  1. package/CameraKit.js +77 -83
  2. package/package.json +2 -2
package/CameraKit.js CHANGED
@@ -1,110 +1,104 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import { StyleSheet, View } from 'react-native';
4
- import { Camera } from 'camerakit';
3
+ import {StyleSheet, View} from 'react-native';
4
+ import {Camera} from 'camerakit';
5
5
 
6
6
  const styles = StyleSheet.create({
7
- container: {
8
- overflow: 'hidden',
9
- },
10
- camera: {
11
- flex: 1,
12
- backgroundColor: 'black'
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
- constructor(props) {
20
- super(props);
21
- this.camera = null;
22
- }
19
+ constructor(props) {
20
+ super(props);
21
+ this.camera = null;
22
+ }
23
23
 
24
- readImageQRCode = (base64) => {
25
- this.camera?.readImageQRCode(base64);
26
- };
24
+ readImageQRCode = base64 => {
25
+ this.camera?.readImageQRCode(base64);
26
+ };
27
27
 
28
- startCamera = () => {
29
- this.camera?.startCamera();
30
- };
28
+ startCamera = () => {
29
+ this.camera?.startCamera();
30
+ };
31
31
 
32
- stopCamera = () => {
33
- this.camera?.stopCamera();
34
- };
32
+ stopCamera = () => {
33
+ this.camera?.stopCamera();
34
+ };
35
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
- }
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
- 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
- };
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
- onOpenCamera = ({ nativeEvent }) => {
59
- const { onOpenCamera } = this.props;
60
- onOpenCamera?.(nativeEvent);
61
- };
58
+ onOpenCamera = ({nativeEvent}) => {
59
+ const {onOpenCamera} = this.props;
60
+ onOpenCamera?.(nativeEvent);
61
+ };
62
62
 
63
- render() {
64
- const {
65
- customFinder,
66
- style,
67
- torchMode,
68
- type,
69
- onBarCodeRead,
70
- zoomMode,
71
- } = this.props;
63
+ render() {
64
+ const {customFinder, style, torchMode, type, onBarCodeRead, zoomMode} =
65
+ this.props;
72
66
 
73
- return (
74
- <View style={[styles.container, style]}>
75
- <Camera
76
- ref={(cam) => (this.camera = cam)}
77
- style={styles.camera}
78
- cameraType={type}
79
- torchMode={torchMode}
80
- focusMode={torchMode}
81
- zoomMode={zoomMode}
82
- scanBarcode={!!onBarCodeRead}
83
- onReadCode={this.onBarCodeRead}
84
- onOpenCamera={this.onOpenCamera}
85
- />
86
- <View style={StyleSheet.absoluteFill}>
87
- {customFinder && customFinder()}
88
- </View>
89
- </View>
90
- );
91
- }
67
+ return (
68
+ <View style={[styles.container, style]}>
69
+ <Camera
70
+ ref={cam => (this.camera = cam)}
71
+ style={styles.camera}
72
+ cameraType={type}
73
+ torchMode={torchMode}
74
+ focusMode={torchMode}
75
+ zoomMode={zoomMode}
76
+ scanBarcode={!!onBarCodeRead}
77
+ onReadCode={this.onBarCodeRead}
78
+ onOpenCamera={this.onOpenCamera}
79
+ />
80
+ {customFinder && (
81
+ <View style={StyleSheet.absoluteFill}>{customFinder()}</View>
82
+ )}
83
+ </View>
84
+ );
85
+ }
92
86
  }
93
87
 
94
88
  CameraKit.propTypes = {
95
- onBarCodeRead: PropTypes.func,
96
- onImageCaptured: PropTypes.func,
97
- type: PropTypes.oneOf(['front', 'back']),
98
- torchMode: PropTypes.oneOf(['on', 'off', 'auto']),
99
- zoomMode: PropTypes.oneOf(['on', 'off']),
100
- onOpenCamera: PropTypes.func,
89
+ onBarCodeRead: PropTypes.func,
90
+ onImageCaptured: PropTypes.func,
91
+ type: PropTypes.oneOf(['front', 'back']),
92
+ torchMode: PropTypes.oneOf(['on', 'off', 'auto']),
93
+ zoomMode: PropTypes.oneOf(['on', 'off']),
94
+ onOpenCamera: PropTypes.func,
101
95
  };
102
96
 
103
97
  CameraKit.defaultProps = {
104
- type: 'back',
105
- torchMode: 'off',
106
- zoomMode: 'off',
107
- onOpenCamera: () => {},
98
+ type: 'back',
99
+ torchMode: 'off',
100
+ zoomMode: 'off',
101
+ onOpenCamera: () => {},
108
102
  };
109
103
 
110
104
  export default CameraKit;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/camerakit",
3
- "version": "0.0.65-beta.30",
3
+ "version": "0.0.65-beta.31",
4
4
  "private": false,
5
5
  "main": "index.js",
6
6
  "dependencies": {
@@ -12,4 +12,4 @@
12
12
  },
13
13
  "devDependencies": {},
14
14
  "license": "MoMo"
15
- }
15
+ }