react-native-rectangle-doc-scanner 3.56.0 → 3.58.0
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/package.json
CHANGED
package/scripts/postinstall.js
CHANGED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
requireNativeComponent,
|
|
4
|
+
NativeModules,
|
|
5
|
+
View,
|
|
6
|
+
Platform,
|
|
7
|
+
PermissionsAndroid,
|
|
8
|
+
DeviceEventEmitter,
|
|
9
|
+
} from 'react-native';
|
|
10
|
+
import PropTypes from 'prop-types';
|
|
11
|
+
|
|
12
|
+
const RNPdfScanner = requireNativeComponent('RNPdfScanner', PdfScanner);
|
|
13
|
+
const CameraManager = NativeModules.RNPdfScannerManager || {};
|
|
14
|
+
|
|
15
|
+
class PdfScanner extends React.Component {
|
|
16
|
+
constructor(props) {
|
|
17
|
+
super(props);
|
|
18
|
+
this.state = {
|
|
19
|
+
permissionsAuthorized: Platform.OS === 'ios',
|
|
20
|
+
};
|
|
21
|
+
this.eventsSubscribed = false;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
onPermissionsDenied = () => {
|
|
25
|
+
if (this.props.onPermissionsDenied) {
|
|
26
|
+
this.props.onPermissionsDenied();
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
componentDidMount() {
|
|
31
|
+
this.subscribeNativeEvents();
|
|
32
|
+
this.getAndroidPermissions();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
componentWillUnmount() {
|
|
36
|
+
this.unsubscribeNativeEvents();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
UNSAFE_componentWillMount() {
|
|
40
|
+
// Keep for backward compatibility in non-StrictMode React versions
|
|
41
|
+
this.subscribeNativeEvents();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
subscribeNativeEvents() {
|
|
45
|
+
if (Platform.OS !== 'android') {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (this.eventsSubscribed) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const { onPictureTaken, onProcessing } = this.props;
|
|
52
|
+
DeviceEventEmitter.addListener('onPictureTaken', onPictureTaken);
|
|
53
|
+
DeviceEventEmitter.addListener('onProcessingChange', onProcessing);
|
|
54
|
+
this.eventsSubscribed = true;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
unsubscribeNativeEvents() {
|
|
58
|
+
if (Platform.OS !== 'android') {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const { onPictureTaken, onProcessing } = this.props;
|
|
62
|
+
DeviceEventEmitter.removeListener('onPictureTaken', onPictureTaken);
|
|
63
|
+
DeviceEventEmitter.removeListener('onProcessingChange', onProcessing);
|
|
64
|
+
this.eventsSubscribed = false;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async getAndroidPermissions() {
|
|
68
|
+
if (Platform.OS !== 'android') {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
const granted = await PermissionsAndroid.requestMultiple([
|
|
73
|
+
PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,
|
|
74
|
+
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
|
|
75
|
+
]);
|
|
76
|
+
|
|
77
|
+
const readGranted =
|
|
78
|
+
granted['android.permission.READ_EXTERNAL_STORAGE'] ===
|
|
79
|
+
PermissionsAndroid.RESULTS.GRANTED;
|
|
80
|
+
const writeGranted =
|
|
81
|
+
granted['android.permission.WRITE_EXTERNAL_STORAGE'] ===
|
|
82
|
+
PermissionsAndroid.RESULTS.GRANTED;
|
|
83
|
+
|
|
84
|
+
if (readGranted && writeGranted) {
|
|
85
|
+
this.setState({ permissionsAuthorized: true });
|
|
86
|
+
} else {
|
|
87
|
+
this.onPermissionsDenied();
|
|
88
|
+
}
|
|
89
|
+
} catch (err) {
|
|
90
|
+
this.onPermissionsDenied();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
static defaultProps = {
|
|
95
|
+
onPictureTaken: () => {},
|
|
96
|
+
onProcessing: () => {},
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
sendOnPictureTakenEvent(event) {
|
|
100
|
+
return this.props.onPictureTaken(event.nativeEvent);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
sendOnRectanleDetectEvent(event) {
|
|
104
|
+
if (!this.props.onRectangleDetect) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
return this.props.onRectangleDetect(event.nativeEvent);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
getImageQuality() {
|
|
111
|
+
if (!this.props.quality) {
|
|
112
|
+
return 0.8;
|
|
113
|
+
}
|
|
114
|
+
if (this.props.quality > 1) {
|
|
115
|
+
return 1;
|
|
116
|
+
}
|
|
117
|
+
if (this.props.quality < 0.1) {
|
|
118
|
+
return 0.1;
|
|
119
|
+
}
|
|
120
|
+
return this.props.quality;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
capture() {
|
|
124
|
+
if (this.state.permissionsAuthorized) {
|
|
125
|
+
CameraManager.capture();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
render() {
|
|
130
|
+
if (!this.state.permissionsAuthorized) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
return (
|
|
134
|
+
<RNPdfScanner
|
|
135
|
+
{...this.props}
|
|
136
|
+
onPictureTaken={this.sendOnPictureTakenEvent.bind(this)}
|
|
137
|
+
onRectangleDetect={this.sendOnRectanleDetectEvent.bind(this)}
|
|
138
|
+
useFrontCam={this.props.useFrontCam || false}
|
|
139
|
+
brightness={this.props.brightness || 0}
|
|
140
|
+
saturation={this.props.saturation || 1}
|
|
141
|
+
contrast={this.props.contrast || 1}
|
|
142
|
+
quality={this.getImageQuality()}
|
|
143
|
+
detectionCountBeforeCapture={this.props.detectionCountBeforeCapture || 5}
|
|
144
|
+
detectionRefreshRateInMS={this.props.detectionRefreshRateInMS || 50}
|
|
145
|
+
/>
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
PdfScanner.propTypes = {
|
|
151
|
+
onPictureTaken: PropTypes.func,
|
|
152
|
+
onRectangleDetect: PropTypes.func,
|
|
153
|
+
overlayColor: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
154
|
+
enableTorch: PropTypes.bool,
|
|
155
|
+
useFrontCam: PropTypes.bool,
|
|
156
|
+
saturation: PropTypes.number,
|
|
157
|
+
brightness: PropTypes.number,
|
|
158
|
+
contrast: PropTypes.number,
|
|
159
|
+
detectionCountBeforeCapture: PropTypes.number,
|
|
160
|
+
detectionRefreshRateInMS: PropTypes.number,
|
|
161
|
+
quality: PropTypes.number,
|
|
162
|
+
documentAnimation: PropTypes.bool,
|
|
163
|
+
noGrayScale: PropTypes.bool,
|
|
164
|
+
manualOnly: PropTypes.bool,
|
|
165
|
+
...View.propTypes,
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
export default PdfScanner;
|
|
@@ -78,6 +78,8 @@
|
|
|
78
78
|
|
|
79
79
|
_lastDetectionType = type;
|
|
80
80
|
|
|
81
|
+
NSLog(@"[DocumentScanner] manualOnly=%@ detectionCount=%ld stableCounter=%ld", self.manualOnly ? @"YES" : @"NO", (long)self.detectionCountBeforeCapture, (long)self.stableCounter);
|
|
82
|
+
|
|
81
83
|
if (self.manualOnly) {
|
|
82
84
|
return;
|
|
83
85
|
}
|