forked from RobertSasak/react-native-openalpr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
109 lines (89 loc) · 2.63 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import React, { Component, PropTypes } from 'react';
import {
NativeModules,
Platform,
StyleSheet,
requireNativeComponent,
View,
} from 'react-native';
const CameraManager = NativeModules.ALPRCameraManager;
const CAMERA_REF = 'camera';
function convertNativeProps(props) {
const newProps = { ...props };
if (typeof props.aspect === 'string') {
newProps.aspect = Camera.constants.Aspect[props.aspect];
}
if (typeof props.torchMode === 'string') {
newProps.torchMode = Camera.constants.TorchMode[props.torchMode];
}
if (typeof props.captureQuality === 'string') {
newProps.captureQuality = Camera.constants.CaptureQuality[props.captureQuality];
}
// delete this prop because we are going to replace it with our own
delete newProps.onPlateRecognized;
return newProps;
}
export default class Camera extends Component {
static constants = {
Aspect: CameraManager.Aspect,
CaptureQuality: CameraManager.CaptureQuality,
TorchMode: CameraManager.TorchMode
};
static propTypes = {
...View.propTypes,
aspect: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number
]),
captureQuality: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number
]),
country: PropTypes.string,
onPlateRecognized: PropTypes.func,
plateOutlineColor: PropTypes.string,
showPlateOutline: PropTypes.bool,
torchMode: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number
]),
touchToFocus: PropTypes.bool,
};
static defaultProps = {
aspect: CameraManager.Aspect.fill,
captureQuality: CameraManager.CaptureQuality.medium,
country: 'us',
plateOutlineColor: '#0028ff',
showPlateOutline: true,
torchMode: CameraManager.TorchMode.off,
touchToFocus: true,
};
static checkVideoAuthorizationStatus = CameraManager.checkVideoAuthorizationStatus;
setNativeProps(props) {
this.refs[CAMERA_REF].setNativeProps(props);
}
constructor() {
super();
this.state = {
isAuthorized: false
};
}
onPlateRecognized = (event) => {
if(this.props.onPlateRecognized) {
this.props.onPlateRecognized(event.nativeEvent);
}
}
async componentWillMount() {
let check = Camera.checkVideoAuthorizationStatus;
if (check) {
const isAuthorized = await check();
this.setState({ isAuthorized });
}
}
render() {
const nativeProps = convertNativeProps(this.props);
return <ALPRCamera ref={CAMERA_REF} onPlateRecognized={this.onPlateRecognized} {...nativeProps} />;
}
}
export const constants = Camera.constants;
const ALPRCamera = requireNativeComponent('ALPRCamera', Camera);