forked from Michaelvilleneuve/react-native-document-scanner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
android.js
57 lines (47 loc) · 1.5 KB
/
android.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, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import {
DeviceEventEmitter, // android
NativeModules,
requireNativeComponent,
View
} from 'react-native';
var iface = {
name: 'DocumentScanner',
propTypes: {
documentAnimation : PropTypes.bool,
detectionCountBeforeCapture : PropTypes.number,
enableTorch : PropTypes.bool,
manualOnly: PropTypes.bool,
overlayColor: PropTypes.string,
contrast: PropTypes.number,
brightness: PropTypes.number,
noGrayScale: PropTypes.bool,
...View.propTypes // include the default view properties
},
};
const DocumentScanner = requireNativeComponent('DocumentScanner', iface);
const CameraManager = NativeModules.DocumentScannerManager || {};
class Scanner extends PureComponent{
static defaultProps = {
onPictureTaken: ()=>{},
onProcessing: ()=>{},
}
componentWillMount(){
const { onPictureTaken, onProcessing } = this.props;
DeviceEventEmitter.addListener('onPictureTaken', onPictureTaken);
DeviceEventEmitter.addListener('onProcessingChange', onProcessing);
}
componentWillUnmount(){
const { onPictureTaken, onProcessing } = this.props;
DeviceEventEmitter.removeListener('onPictureTaken', onPictureTaken);
DeviceEventEmitter.removeListener('onProcessingChange', onProcessing);
}
capture = ()=>{
CameraManager.capture();
}
render(){
return <DocumentScanner {...this.props}/>
}
}
export default Scanner;