-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathindex.js
57 lines (52 loc) · 1.53 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
import React,{Component} from 'react';
import { NativeModules,
requireNativeComponent,
View,
DeviceEventEmitter
} from 'react-native';
import PropTypes from 'prop-types'
const SunmiInnerScanner = NativeModules.SunmiInnerScanner;
export default SunmiInnerScanner;
export class SunmiScannerView extends Component {
componentWillMount() {
if (this.props.onCodeScan){
this.cameraBarCodeReadListener = DeviceEventEmitter.addListener('SunmiInnerScannerView.RESULT',
(data)=> {
this.props.onCodeScan(data.result || []);
});
}
}
componentWillUnmount() {
if (this.cameraBarCodeReadListener) {
this.cameraBarCodeReadListener.remove();
}
}
static propTypes = {
...View.propTypes,
xDensity: PropTypes.number,
yDensity: PropTypes.number,
mutilScanEnable: PropTypes.number,
inverseEnable: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number
]),
onCodeScan: PropTypes.func,
scanInterval: PropTypes.number,
mute: PropTypes.number
};
static defaultProps = {
xDensity: 2,
yDensity: 2,
mutilScanEnable: 0,
inverseEnable: 1,
onCodeScan: function (result) {
console.log(result);
},
scanInterval:1000,
mute:0
}
render() {
return <SunmiScanner {...this.props} />;
}
}
const SunmiScanner = requireNativeComponent('SunmiScanner', SunmiScannerView);