@react-native-ohos/react-native-qr-decode-image-camera 1.1.4-rc.1 → 1.1.4-rc.2
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/.github/workflows/codeql-analysis.yml +68 -0
- package/COMMITTERS.md +6 -6
- package/LICENSE +21 -21
- package/OAT.xml +88 -88
- package/QrCode.podspec +14 -14
- package/README.OpenSource +10 -10
- package/README.md +13 -13
- package/SECURITY.md +21 -21
- package/harmony/qr_decode_image_camera/BuildProfile.ets +16 -16
- package/harmony/qr_decode_image_camera/Index.ets +7 -7
- package/harmony/qr_decode_image_camera/build-profile.json5 +27 -27
- package/harmony/qr_decode_image_camera/obfuscation-rules.txt +17 -17
- package/harmony/qr_decode_image_camera/oh-package-lock.json5 +17 -17
- package/harmony/qr_decode_image_camera/oh-package.json5 +12 -12
- package/harmony/qr_decode_image_camera/src/main/cpp/generated/RNOH/generated/BaseReactNativeQrDecodeImageCameraPackage.h +72 -72
- package/harmony/qr_decode_image_camera/src/main/cpp/generated/RNOH/generated/turbo_modules/QrDecodeImageCameraNativeModule.cpp +16 -16
- package/harmony/qr_decode_image_camera/src/main/cpp/generated/RNOH/generated/turbo_modules/QrDecodeImageCameraNativeModule.h +16 -16
- package/harmony/qr_decode_image_camera/src/main/cpp/generated/react/renderer/components/react_native_qr_decode_image_camera/ComponentDescriptors.h +24 -24
- package/harmony/qr_decode_image_camera/src/main/cpp/generated/react/renderer/components/react_native_qr_decode_image_camera/EventEmitters.cpp +16 -16
- package/harmony/qr_decode_image_camera/src/main/cpp/generated/react/renderer/components/react_native_qr_decode_image_camera/EventEmitters.h +17 -17
- package/harmony/qr_decode_image_camera/src/main/cpp/generated/react/renderer/components/react_native_qr_decode_image_camera/Props.cpp +19 -19
- package/harmony/qr_decode_image_camera/src/main/cpp/generated/react/renderer/components/react_native_qr_decode_image_camera/Props.h +18 -18
- package/harmony/qr_decode_image_camera/src/main/cpp/generated/react/renderer/components/react_native_qr_decode_image_camera/ShadowNodes.cpp +17 -17
- package/harmony/qr_decode_image_camera/src/main/cpp/generated/react/renderer/components/react_native_qr_decode_image_camera/ShadowNodes.h +23 -23
- package/harmony/qr_decode_image_camera/src/main/cpp/generated/react/renderer/components/react_native_qr_decode_image_camera/States.cpp +16 -16
- package/harmony/qr_decode_image_camera/src/main/cpp/generated/react/renderer/components/react_native_qr_decode_image_camera/States.h +18 -18
- package/harmony/qr_decode_image_camera/src/main/ets/Logger.ts +45 -45
- package/harmony/qr_decode_image_camera/src/main/ets/NativeScan.ets +150 -150
- package/harmony/qr_decode_image_camera/src/main/ets/RNQrDecodeImageCameraPackage.ts +28 -28
- package/harmony/qr_decode_image_camera/src/main/ets/RNQrDecodeImageCameraTurboModule.ts +46 -46
- package/harmony/qr_decode_image_camera/src/main/ets/generated/components/NativeScan.ts +125 -125
- package/harmony/qr_decode_image_camera/src/main/ets/generated/components/ts.ts +8 -8
- package/harmony/qr_decode_image_camera/src/main/ets/generated/index.ets +5 -5
- package/harmony/qr_decode_image_camera/src/main/ets/generated/ts.ts +6 -6
- package/harmony/qr_decode_image_camera/src/main/ets/generated/turboModules/QrDecodeImageCameraNativeModule.ts +16 -16
- package/harmony/qr_decode_image_camera/src/main/ets/generated/turboModules/ts.ts +5 -5
- package/harmony/qr_decode_image_camera/src/main/ets/pages/Index.ets +25 -25
- package/harmony/qr_decode_image_camera/src/main/ets/qr_decode_image_camera/qr_decode_image_camera.ets +47 -47
- package/harmony/qr_decode_image_camera/src/main/module.json5 +10 -10
- package/harmony/qr_decode_image_camera/src/main/resources/base/element/color.json +7 -7
- package/harmony/qr_decode_image_camera/src/main/resources/base/element/string.json +15 -15
- package/harmony/qr_decode_image_camera/src/main/resources/base/media/layered_image.json +6 -6
- package/harmony/qr_decode_image_camera/src/main/resources/base/profile/main_pages.json +5 -5
- package/harmony/qr_decode_image_camera/src/main/resources/en_US/element/string.json +15 -15
- package/harmony/qr_decode_image_camera/src/main/resources/zh_CN/element/string.json +15 -15
- package/harmony/qr_decode_image_camera/src/mock/mock-config.json5 +1 -1
- package/harmony/qr_decode_image_camera/src/ohosTest/ets/test/Ability.test.ets +34 -34
- package/harmony/qr_decode_image_camera/src/ohosTest/ets/test/List.test.ets +4 -4
- package/harmony/qr_decode_image_camera/src/ohosTest/ets/testability/TestAbility.ets +46 -46
- package/harmony/qr_decode_image_camera/src/ohosTest/ets/testability/pages/Index.ets +16 -16
- package/harmony/qr_decode_image_camera/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ets +89 -89
- package/harmony/qr_decode_image_camera/src/ohosTest/module.json5 +36 -36
- package/harmony/qr_decode_image_camera/src/ohosTest/resources/base/element/color.json +7 -7
- package/harmony/qr_decode_image_camera/src/ohosTest/resources/base/element/string.json +15 -15
- package/harmony/qr_decode_image_camera/src/ohosTest/resources/base/profile/test_pages.json +5 -5
- package/harmony/qr_decode_image_camera/src/test/List.test.ets +4 -4
- package/harmony/qr_decode_image_camera/src/test/LocalUnit.test.ets +32 -32
- package/harmony/qr_decode_image_camera/ts.ts +7 -7
- package/index.js +14 -14
- package/package.json +39 -39
- package/src/Camera.tsx +57 -57
- package/src/NativeQrDecodeImageCamera.ts +16 -16
- package/src/NativeScan.ts +24 -24
- package/src/QRScanner.harmony.jsx +223 -225
- package/src/QRScanner.jsx +281 -281
- package/src/QRScannerView.js +382 -381
package/src/QRScanner.jsx
CHANGED
|
@@ -1,281 +1,281 @@
|
|
|
1
|
-
import React, { PureComponent, Component } from "react";
|
|
2
|
-
import { RNCamera } from "react-native-camera";
|
|
3
|
-
import PropTypes from "prop-types";
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
StyleSheet,
|
|
7
|
-
View,
|
|
8
|
-
Text,
|
|
9
|
-
Vibration,
|
|
10
|
-
Platform,
|
|
11
|
-
} from "react-native";
|
|
12
|
-
import QRScannerView from "./QRScannerView";
|
|
13
|
-
import QRScannerHarmony from "./QRScanner.harmony.jsx"
|
|
14
|
-
/**
|
|
15
|
-
* Scan interface
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export default class QRScanner extends Component {
|
|
20
|
-
|
|
21
|
-
constructor(props) {
|
|
22
|
-
super(props);
|
|
23
|
-
this.state = {
|
|
24
|
-
scanning: false,
|
|
25
|
-
barCodeSize: {}
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
static defaultProps = {
|
|
30
|
-
onRead: () => { },
|
|
31
|
-
renderTopView: () => { },
|
|
32
|
-
renderBottomView: () => (
|
|
33
|
-
<View style={{ flex: 1, backgroundColor: "#0000004D" }} />
|
|
34
|
-
),
|
|
35
|
-
rectHeight: 200,
|
|
36
|
-
rectWidth: 200,
|
|
37
|
-
flashMode: false, // Flashlight mode
|
|
38
|
-
finderX: 0, // Viewfinder X-axis offset
|
|
39
|
-
finderY: 0, // Viewfinder Y-axis offset
|
|
40
|
-
zoom: 0.2, // Zoom range 0 - 1
|
|
41
|
-
translucent: false,
|
|
42
|
-
isRepeatScan: false,
|
|
43
|
-
cameraType: "back",
|
|
44
|
-
notAuthorizedView: () => (
|
|
45
|
-
<View style={styles.authorizationContainer}>
|
|
46
|
-
<Text style={styles.notAuthorizedText}>Camera not authorized</Text>
|
|
47
|
-
</View>
|
|
48
|
-
),
|
|
49
|
-
vibrate: true,
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
render() {
|
|
53
|
-
if (Platform.OS == 'harmony') {
|
|
54
|
-
return (
|
|
55
|
-
<QRScannerHarmony {...this.props} />
|
|
56
|
-
)
|
|
57
|
-
} else {
|
|
58
|
-
return (
|
|
59
|
-
<View
|
|
60
|
-
style={{
|
|
61
|
-
flex: 1
|
|
62
|
-
}}
|
|
63
|
-
>
|
|
64
|
-
<RNCamera
|
|
65
|
-
style={{
|
|
66
|
-
flex: 1
|
|
67
|
-
}}
|
|
68
|
-
captureAudio={false}
|
|
69
|
-
onBarCodeRead={this._handleBarCodeRead}
|
|
70
|
-
androidCameraPermissionOptions={null}
|
|
71
|
-
androidRecordAudioPermissionOptions={null}
|
|
72
|
-
notAuthorizedView={this.props.notAuthorizedView()}
|
|
73
|
-
barCodeTypes={[RNCamera.Constants.BarCodeType.qr]}
|
|
74
|
-
flashMode={
|
|
75
|
-
!this.props.flashMode
|
|
76
|
-
? RNCamera.Constants.FlashMode.off
|
|
77
|
-
: RNCamera.Constants.FlashMode.torch
|
|
78
|
-
}
|
|
79
|
-
zoom={this.props.zoom}
|
|
80
|
-
type={this.props.cameraType}
|
|
81
|
-
>
|
|
82
|
-
<View style={[styles.topButtonsContainer, this.props.topViewStyle]}>
|
|
83
|
-
{this.props.renderTopView()}
|
|
84
|
-
</View>
|
|
85
|
-
<QRScannerView
|
|
86
|
-
maskColor={this.props.maskColor}
|
|
87
|
-
cornerColor={this.props.cornerColor}
|
|
88
|
-
borderColor={this.props.borderColor}
|
|
89
|
-
rectHeight={this.props.rectHeight}
|
|
90
|
-
rectWidth={this.props.rectWidth}
|
|
91
|
-
borderWidth={this.props.borderWidth}
|
|
92
|
-
cornerBorderWidth={this.props.cornerBorderWidth}
|
|
93
|
-
cornerBorderLength={this.props.cornerBorderLength}
|
|
94
|
-
cornerOffsetSize={this.props.cornerOffsetSize}
|
|
95
|
-
isCornerOffset={this.props.isCornerOffset}
|
|
96
|
-
bottomHeight={this.props.bottomHeight}
|
|
97
|
-
scanBarAnimateTime={this.props.scanBarAnimateTime}
|
|
98
|
-
scanBarColor={this.props.scanBarColor}
|
|
99
|
-
scanBarHeight={this.props.scanBarHeight}
|
|
100
|
-
scanBarMargin={this.props.scanBarMargin}
|
|
101
|
-
hintText={this.props.hintText}
|
|
102
|
-
hintTextStyle={this.props.hintTextStyle}
|
|
103
|
-
scanBarImage={this.props.scanBarImage}
|
|
104
|
-
hintTextPosition={this.props.hintTextPosition}
|
|
105
|
-
isShowScanBar={this.props.isShowScanBar}
|
|
106
|
-
finderX={this.props.finderX}
|
|
107
|
-
finderY={this.props.finderY}
|
|
108
|
-
returnSize={this.barCodeSize}
|
|
109
|
-
/>
|
|
110
|
-
<View
|
|
111
|
-
style={[styles.bottomButtonsContainer, this.props.bottomViewStyle]}
|
|
112
|
-
>
|
|
113
|
-
{this.props.renderBottomView()}
|
|
114
|
-
</View>
|
|
115
|
-
</RNCamera>
|
|
116
|
-
</View>
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
isShowCode = false;
|
|
123
|
-
|
|
124
|
-
barCodeSize = size => this.setState({ barCodeSize: size });
|
|
125
|
-
|
|
126
|
-
returnMax = (a, b) => (a > b ? a : b);
|
|
127
|
-
|
|
128
|
-
returnMin = (a, b) => (a < b ? a : b);
|
|
129
|
-
|
|
130
|
-
iosBarCode = e => {
|
|
131
|
-
let x = Number(e.bounds.origin.x);
|
|
132
|
-
let y = Number(e.bounds.origin.y);
|
|
133
|
-
let width = e.bounds.size.width;
|
|
134
|
-
let height = e.bounds.size.height;
|
|
135
|
-
let viewMinX = this.state.barCodeSize.x - this.props.finderX;
|
|
136
|
-
let viewMinY = this.state.barCodeSize.y - this.props.finderY;
|
|
137
|
-
let viewMaxX =
|
|
138
|
-
this.state.barCodeSize.x +
|
|
139
|
-
this.state.barCodeSize.width -
|
|
140
|
-
width -
|
|
141
|
-
this.props.finderX;
|
|
142
|
-
let viewMaxY =
|
|
143
|
-
this.state.barCodeSize.y +
|
|
144
|
-
this.state.barCodeSize.height -
|
|
145
|
-
height -
|
|
146
|
-
this.props.finderY;
|
|
147
|
-
if (x > viewMinX && y > viewMinY && x < viewMaxX && y < viewMaxY) {
|
|
148
|
-
if (this.props.isRepeatScan) {
|
|
149
|
-
if (this.props.vibrate) {
|
|
150
|
-
Vibration.vibrate();
|
|
151
|
-
}
|
|
152
|
-
this.props.onRead(e);
|
|
153
|
-
} else {
|
|
154
|
-
if (!this.isShowCode) {
|
|
155
|
-
this.isShowCode = true;
|
|
156
|
-
if (this.props.vibrate) {
|
|
157
|
-
Vibration.vibrate();
|
|
158
|
-
}
|
|
159
|
-
this.props.onRead(e);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
androidBarCode = e => {
|
|
166
|
-
// if (!e.bounds[0] || !e.bounds[1] || !e.bounds[2] || !e.bounds[3]) return null;
|
|
167
|
-
// const leftBottom = {x: e.bounds[0].x / pixelRatio, y: e.bounds[0].y / pixelRatio}
|
|
168
|
-
// const leftTop= {x: e.bounds[1].x / pixelRatio, y: e.bounds[1].y / pixelRatio}
|
|
169
|
-
// const rightTop = {x: e.bounds[2].x / pixelRatio, y: e.bounds[2].y / pixelRatio}
|
|
170
|
-
// const rightBottom = {x: e.bounds[3].x / pixelRatio, y: e.bounds[3].y / pixelRatio}
|
|
171
|
-
// let x = this.returnMin(leftTop.x, leftBottom.x);
|
|
172
|
-
// let y = this.returnMin(leftTop.y, rightTop.y);
|
|
173
|
-
// let width = this.returnMax(rightTop.x - leftTop.x, rightBottom.x - leftBottom.x)
|
|
174
|
-
// let height = this.returnMax(leftBottom.y - leftTop.y , rightBottom.y - rightTop.y)
|
|
175
|
-
// let viewMinX = this.state.barCodeSize.x - this.props.finderX * 4 / pixelRatio - (this.props.finderX > 0 ? this.props.finderX/10 : 0)
|
|
176
|
-
// let viewMinY = this.state.barCodeSize.y - this.props.finderY * 4 / pixelRatio - (this.props.translucent ? 0 : StatusBar.currentHeight)*2/pixelRatio - (this.props.finderY > 0 ? this.props.finderY/3 : this.props.finderY/10*(-1))
|
|
177
|
-
// let viewMaxX = this.state.barCodeSize.x + 20 + this.state.barCodeSize.width*2 / pixelRatio - width - this.props.finderX *4/pixelRatio - (this.props.finderX < 0 ? 0 : this.props.finderX/5)
|
|
178
|
-
// let viewMaxY = this.state.barCodeSize.y + this.state.barCodeSize.height*2 / pixelRatio - height - this.props.finderY *4/pixelRatio - (this.props.translucent ? 0 : StatusBar.currentHeight)*2/pixelRatio - (this.props.finderY < 0 ? this.props.finderY/5 : 0 )
|
|
179
|
-
// if(x&&y) {
|
|
180
|
-
// if ((x > viewMinX && y > viewMinY) && (x < viewMaxX && y < viewMaxY)) {
|
|
181
|
-
// if (this.props.isRepeatScan) {
|
|
182
|
-
// Vibration.vibrate();
|
|
183
|
-
// this.props.onRead(e)
|
|
184
|
-
// } else {
|
|
185
|
-
// if (!this.isShowCode) {
|
|
186
|
-
// this.isShowCode = true;
|
|
187
|
-
// Vibration.vibrate();
|
|
188
|
-
// this.props.onRead(e)
|
|
189
|
-
// }
|
|
190
|
-
// }
|
|
191
|
-
// }
|
|
192
|
-
// }
|
|
193
|
-
|
|
194
|
-
// The following are unrestricted scanning areas
|
|
195
|
-
if (this.props.isRepeatScan) {
|
|
196
|
-
Vibration.vibrate();
|
|
197
|
-
this.props.onRead(e);
|
|
198
|
-
} else {
|
|
199
|
-
if (!this.isShowCode) {
|
|
200
|
-
this.isShowCode = true;
|
|
201
|
-
Vibration.vibrate();
|
|
202
|
-
this.props.onRead(e);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
_handleBarCodeRead = e => {
|
|
208
|
-
switch (Platform.OS) {
|
|
209
|
-
case "ios":
|
|
210
|
-
this.iosBarCode(e);
|
|
211
|
-
break;
|
|
212
|
-
case "android":
|
|
213
|
-
this.androidBarCode(e);
|
|
214
|
-
break;
|
|
215
|
-
default:
|
|
216
|
-
break;
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
const styles = StyleSheet.create({
|
|
222
|
-
topButtonsContainer: {
|
|
223
|
-
position: "absolute",
|
|
224
|
-
height: 100,
|
|
225
|
-
top: 0,
|
|
226
|
-
left: 0,
|
|
227
|
-
right: 0
|
|
228
|
-
},
|
|
229
|
-
bottomButtonsContainer: {
|
|
230
|
-
position: "absolute",
|
|
231
|
-
height: 100,
|
|
232
|
-
bottom: 0,
|
|
233
|
-
left: 0,
|
|
234
|
-
right: 0
|
|
235
|
-
},
|
|
236
|
-
authorizationContainer: {
|
|
237
|
-
flex: 1,
|
|
238
|
-
alignItems: "center",
|
|
239
|
-
justifyContent: "center"
|
|
240
|
-
},
|
|
241
|
-
notAuthorizedText: {
|
|
242
|
-
textAlign: "center",
|
|
243
|
-
fontSize: 16
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
QRScanner.propTypes = {
|
|
248
|
-
isRepeatScan: PropTypes.bool,
|
|
249
|
-
onRead: PropTypes.func,
|
|
250
|
-
maskColor: PropTypes.string,
|
|
251
|
-
borderColor: PropTypes.string,
|
|
252
|
-
cornerColor: PropTypes.string,
|
|
253
|
-
borderWidth: PropTypes.number,
|
|
254
|
-
cornerBorderWidth: PropTypes.number,
|
|
255
|
-
cornerBorderLength: PropTypes.number,
|
|
256
|
-
rectHeight: PropTypes.number,
|
|
257
|
-
rectWidth: PropTypes.number,
|
|
258
|
-
isCornerOffset: PropTypes.bool, //Whether the corners are offset
|
|
259
|
-
cornerOffsetSize: PropTypes.number,
|
|
260
|
-
bottomHeight: PropTypes.number,
|
|
261
|
-
scanBarAnimateTime: PropTypes.number,
|
|
262
|
-
scanBarColor: PropTypes.string,
|
|
263
|
-
scanBarImage: PropTypes.any,
|
|
264
|
-
scanBarHeight: PropTypes.number,
|
|
265
|
-
scanBarMargin: PropTypes.number,
|
|
266
|
-
hintText: PropTypes.string,
|
|
267
|
-
hintTextStyle: PropTypes.object,
|
|
268
|
-
hintTextPosition: PropTypes.number,
|
|
269
|
-
renderTopView: PropTypes.func,
|
|
270
|
-
renderBottomView: PropTypes.func,
|
|
271
|
-
isShowScanBar: PropTypes.bool,
|
|
272
|
-
topViewStyle: PropTypes.object,
|
|
273
|
-
bottomViewStyle: PropTypes.object,
|
|
274
|
-
flashMode: PropTypes.bool,
|
|
275
|
-
finderX: PropTypes.number,
|
|
276
|
-
finderY: PropTypes.number,
|
|
277
|
-
zoom: PropTypes.number,
|
|
278
|
-
translucent: PropTypes.bool,
|
|
279
|
-
cameraType: PropTypes.string,
|
|
280
|
-
vibrate: PropTypes.bool,
|
|
281
|
-
};
|
|
1
|
+
import React, { PureComponent, Component } from "react";
|
|
2
|
+
import { RNCamera } from "react-native-camera";
|
|
3
|
+
import PropTypes from "prop-types";
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
StyleSheet,
|
|
7
|
+
View,
|
|
8
|
+
Text,
|
|
9
|
+
Vibration,
|
|
10
|
+
Platform,
|
|
11
|
+
} from "react-native";
|
|
12
|
+
import QRScannerView from "./QRScannerView";
|
|
13
|
+
import QRScannerHarmony from "./QRScanner.harmony.jsx"
|
|
14
|
+
/**
|
|
15
|
+
* Scan interface
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
export default class QRScanner extends Component {
|
|
20
|
+
|
|
21
|
+
constructor(props) {
|
|
22
|
+
super(props);
|
|
23
|
+
this.state = {
|
|
24
|
+
scanning: false,
|
|
25
|
+
barCodeSize: {}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static defaultProps = {
|
|
30
|
+
onRead: () => { },
|
|
31
|
+
renderTopView: () => { },
|
|
32
|
+
renderBottomView: () => (
|
|
33
|
+
<View style={{ flex: 1, backgroundColor: "#0000004D" }} />
|
|
34
|
+
),
|
|
35
|
+
rectHeight: 200,
|
|
36
|
+
rectWidth: 200,
|
|
37
|
+
flashMode: false, // Flashlight mode
|
|
38
|
+
finderX: 0, // Viewfinder X-axis offset
|
|
39
|
+
finderY: 0, // Viewfinder Y-axis offset
|
|
40
|
+
zoom: 0.2, // Zoom range 0 - 1
|
|
41
|
+
translucent: false,
|
|
42
|
+
isRepeatScan: false,
|
|
43
|
+
cameraType: "back",
|
|
44
|
+
notAuthorizedView: () => (
|
|
45
|
+
<View style={styles.authorizationContainer}>
|
|
46
|
+
<Text style={styles.notAuthorizedText}>Camera not authorized</Text>
|
|
47
|
+
</View>
|
|
48
|
+
),
|
|
49
|
+
vibrate: true,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
render() {
|
|
53
|
+
if (Platform.OS == 'harmony') {
|
|
54
|
+
return (
|
|
55
|
+
<QRScannerHarmony {...this.props} />
|
|
56
|
+
)
|
|
57
|
+
} else {
|
|
58
|
+
return (
|
|
59
|
+
<View
|
|
60
|
+
style={{
|
|
61
|
+
flex: 1
|
|
62
|
+
}}
|
|
63
|
+
>
|
|
64
|
+
<RNCamera
|
|
65
|
+
style={{
|
|
66
|
+
flex: 1
|
|
67
|
+
}}
|
|
68
|
+
captureAudio={false}
|
|
69
|
+
onBarCodeRead={this._handleBarCodeRead}
|
|
70
|
+
androidCameraPermissionOptions={null}
|
|
71
|
+
androidRecordAudioPermissionOptions={null}
|
|
72
|
+
notAuthorizedView={this.props.notAuthorizedView()}
|
|
73
|
+
barCodeTypes={[RNCamera.Constants.BarCodeType.qr]}
|
|
74
|
+
flashMode={
|
|
75
|
+
!this.props.flashMode
|
|
76
|
+
? RNCamera.Constants.FlashMode.off
|
|
77
|
+
: RNCamera.Constants.FlashMode.torch
|
|
78
|
+
}
|
|
79
|
+
zoom={this.props.zoom}
|
|
80
|
+
type={this.props.cameraType}
|
|
81
|
+
>
|
|
82
|
+
<View style={[styles.topButtonsContainer, this.props.topViewStyle]}>
|
|
83
|
+
{this.props.renderTopView()}
|
|
84
|
+
</View>
|
|
85
|
+
<QRScannerView
|
|
86
|
+
maskColor={this.props.maskColor}
|
|
87
|
+
cornerColor={this.props.cornerColor}
|
|
88
|
+
borderColor={this.props.borderColor}
|
|
89
|
+
rectHeight={this.props.rectHeight}
|
|
90
|
+
rectWidth={this.props.rectWidth}
|
|
91
|
+
borderWidth={this.props.borderWidth}
|
|
92
|
+
cornerBorderWidth={this.props.cornerBorderWidth}
|
|
93
|
+
cornerBorderLength={this.props.cornerBorderLength}
|
|
94
|
+
cornerOffsetSize={this.props.cornerOffsetSize}
|
|
95
|
+
isCornerOffset={this.props.isCornerOffset}
|
|
96
|
+
bottomHeight={this.props.bottomHeight}
|
|
97
|
+
scanBarAnimateTime={this.props.scanBarAnimateTime}
|
|
98
|
+
scanBarColor={this.props.scanBarColor}
|
|
99
|
+
scanBarHeight={this.props.scanBarHeight}
|
|
100
|
+
scanBarMargin={this.props.scanBarMargin}
|
|
101
|
+
hintText={this.props.hintText}
|
|
102
|
+
hintTextStyle={this.props.hintTextStyle}
|
|
103
|
+
scanBarImage={this.props.scanBarImage}
|
|
104
|
+
hintTextPosition={this.props.hintTextPosition}
|
|
105
|
+
isShowScanBar={this.props.isShowScanBar}
|
|
106
|
+
finderX={this.props.finderX}
|
|
107
|
+
finderY={this.props.finderY}
|
|
108
|
+
returnSize={this.barCodeSize}
|
|
109
|
+
/>
|
|
110
|
+
<View
|
|
111
|
+
style={[styles.bottomButtonsContainer, this.props.bottomViewStyle]}
|
|
112
|
+
>
|
|
113
|
+
{this.props.renderBottomView()}
|
|
114
|
+
</View>
|
|
115
|
+
</RNCamera>
|
|
116
|
+
</View>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
isShowCode = false;
|
|
123
|
+
|
|
124
|
+
barCodeSize = size => this.setState({ barCodeSize: size });
|
|
125
|
+
|
|
126
|
+
returnMax = (a, b) => (a > b ? a : b);
|
|
127
|
+
|
|
128
|
+
returnMin = (a, b) => (a < b ? a : b);
|
|
129
|
+
|
|
130
|
+
iosBarCode = e => {
|
|
131
|
+
let x = Number(e.bounds.origin.x);
|
|
132
|
+
let y = Number(e.bounds.origin.y);
|
|
133
|
+
let width = e.bounds.size.width;
|
|
134
|
+
let height = e.bounds.size.height;
|
|
135
|
+
let viewMinX = this.state.barCodeSize.x - this.props.finderX;
|
|
136
|
+
let viewMinY = this.state.barCodeSize.y - this.props.finderY;
|
|
137
|
+
let viewMaxX =
|
|
138
|
+
this.state.barCodeSize.x +
|
|
139
|
+
this.state.barCodeSize.width -
|
|
140
|
+
width -
|
|
141
|
+
this.props.finderX;
|
|
142
|
+
let viewMaxY =
|
|
143
|
+
this.state.barCodeSize.y +
|
|
144
|
+
this.state.barCodeSize.height -
|
|
145
|
+
height -
|
|
146
|
+
this.props.finderY;
|
|
147
|
+
if (x > viewMinX && y > viewMinY && x < viewMaxX && y < viewMaxY) {
|
|
148
|
+
if (this.props.isRepeatScan) {
|
|
149
|
+
if (this.props.vibrate) {
|
|
150
|
+
Vibration.vibrate();
|
|
151
|
+
}
|
|
152
|
+
this.props.onRead(e);
|
|
153
|
+
} else {
|
|
154
|
+
if (!this.isShowCode) {
|
|
155
|
+
this.isShowCode = true;
|
|
156
|
+
if (this.props.vibrate) {
|
|
157
|
+
Vibration.vibrate();
|
|
158
|
+
}
|
|
159
|
+
this.props.onRead(e);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
androidBarCode = e => {
|
|
166
|
+
// if (!e.bounds[0] || !e.bounds[1] || !e.bounds[2] || !e.bounds[3]) return null;
|
|
167
|
+
// const leftBottom = {x: e.bounds[0].x / pixelRatio, y: e.bounds[0].y / pixelRatio}
|
|
168
|
+
// const leftTop= {x: e.bounds[1].x / pixelRatio, y: e.bounds[1].y / pixelRatio}
|
|
169
|
+
// const rightTop = {x: e.bounds[2].x / pixelRatio, y: e.bounds[2].y / pixelRatio}
|
|
170
|
+
// const rightBottom = {x: e.bounds[3].x / pixelRatio, y: e.bounds[3].y / pixelRatio}
|
|
171
|
+
// let x = this.returnMin(leftTop.x, leftBottom.x);
|
|
172
|
+
// let y = this.returnMin(leftTop.y, rightTop.y);
|
|
173
|
+
// let width = this.returnMax(rightTop.x - leftTop.x, rightBottom.x - leftBottom.x)
|
|
174
|
+
// let height = this.returnMax(leftBottom.y - leftTop.y , rightBottom.y - rightTop.y)
|
|
175
|
+
// let viewMinX = this.state.barCodeSize.x - this.props.finderX * 4 / pixelRatio - (this.props.finderX > 0 ? this.props.finderX/10 : 0)
|
|
176
|
+
// let viewMinY = this.state.barCodeSize.y - this.props.finderY * 4 / pixelRatio - (this.props.translucent ? 0 : StatusBar.currentHeight)*2/pixelRatio - (this.props.finderY > 0 ? this.props.finderY/3 : this.props.finderY/10*(-1))
|
|
177
|
+
// let viewMaxX = this.state.barCodeSize.x + 20 + this.state.barCodeSize.width*2 / pixelRatio - width - this.props.finderX *4/pixelRatio - (this.props.finderX < 0 ? 0 : this.props.finderX/5)
|
|
178
|
+
// let viewMaxY = this.state.barCodeSize.y + this.state.barCodeSize.height*2 / pixelRatio - height - this.props.finderY *4/pixelRatio - (this.props.translucent ? 0 : StatusBar.currentHeight)*2/pixelRatio - (this.props.finderY < 0 ? this.props.finderY/5 : 0 )
|
|
179
|
+
// if(x&&y) {
|
|
180
|
+
// if ((x > viewMinX && y > viewMinY) && (x < viewMaxX && y < viewMaxY)) {
|
|
181
|
+
// if (this.props.isRepeatScan) {
|
|
182
|
+
// Vibration.vibrate();
|
|
183
|
+
// this.props.onRead(e)
|
|
184
|
+
// } else {
|
|
185
|
+
// if (!this.isShowCode) {
|
|
186
|
+
// this.isShowCode = true;
|
|
187
|
+
// Vibration.vibrate();
|
|
188
|
+
// this.props.onRead(e)
|
|
189
|
+
// }
|
|
190
|
+
// }
|
|
191
|
+
// }
|
|
192
|
+
// }
|
|
193
|
+
|
|
194
|
+
// The following are unrestricted scanning areas
|
|
195
|
+
if (this.props.isRepeatScan) {
|
|
196
|
+
Vibration.vibrate();
|
|
197
|
+
this.props.onRead(e);
|
|
198
|
+
} else {
|
|
199
|
+
if (!this.isShowCode) {
|
|
200
|
+
this.isShowCode = true;
|
|
201
|
+
Vibration.vibrate();
|
|
202
|
+
this.props.onRead(e);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
_handleBarCodeRead = e => {
|
|
208
|
+
switch (Platform.OS) {
|
|
209
|
+
case "ios":
|
|
210
|
+
this.iosBarCode(e);
|
|
211
|
+
break;
|
|
212
|
+
case "android":
|
|
213
|
+
this.androidBarCode(e);
|
|
214
|
+
break;
|
|
215
|
+
default:
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const styles = StyleSheet.create({
|
|
222
|
+
topButtonsContainer: {
|
|
223
|
+
position: "absolute",
|
|
224
|
+
height: 100,
|
|
225
|
+
top: 0,
|
|
226
|
+
left: 0,
|
|
227
|
+
right: 0
|
|
228
|
+
},
|
|
229
|
+
bottomButtonsContainer: {
|
|
230
|
+
position: "absolute",
|
|
231
|
+
height: 100,
|
|
232
|
+
bottom: 0,
|
|
233
|
+
left: 0,
|
|
234
|
+
right: 0
|
|
235
|
+
},
|
|
236
|
+
authorizationContainer: {
|
|
237
|
+
flex: 1,
|
|
238
|
+
alignItems: "center",
|
|
239
|
+
justifyContent: "center"
|
|
240
|
+
},
|
|
241
|
+
notAuthorizedText: {
|
|
242
|
+
textAlign: "center",
|
|
243
|
+
fontSize: 16
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
QRScanner.propTypes = {
|
|
248
|
+
isRepeatScan: PropTypes.bool,
|
|
249
|
+
onRead: PropTypes.func,
|
|
250
|
+
maskColor: PropTypes.string,
|
|
251
|
+
borderColor: PropTypes.string,
|
|
252
|
+
cornerColor: PropTypes.string,
|
|
253
|
+
borderWidth: PropTypes.number,
|
|
254
|
+
cornerBorderWidth: PropTypes.number,
|
|
255
|
+
cornerBorderLength: PropTypes.number,
|
|
256
|
+
rectHeight: PropTypes.number,
|
|
257
|
+
rectWidth: PropTypes.number,
|
|
258
|
+
isCornerOffset: PropTypes.bool, //Whether the corners are offset
|
|
259
|
+
cornerOffsetSize: PropTypes.number,
|
|
260
|
+
bottomHeight: PropTypes.number,
|
|
261
|
+
scanBarAnimateTime: PropTypes.number,
|
|
262
|
+
scanBarColor: PropTypes.string,
|
|
263
|
+
scanBarImage: PropTypes.any,
|
|
264
|
+
scanBarHeight: PropTypes.number,
|
|
265
|
+
scanBarMargin: PropTypes.number,
|
|
266
|
+
hintText: PropTypes.string,
|
|
267
|
+
hintTextStyle: PropTypes.object,
|
|
268
|
+
hintTextPosition: PropTypes.number,
|
|
269
|
+
renderTopView: PropTypes.func,
|
|
270
|
+
renderBottomView: PropTypes.func,
|
|
271
|
+
isShowScanBar: PropTypes.bool,
|
|
272
|
+
topViewStyle: PropTypes.object,
|
|
273
|
+
bottomViewStyle: PropTypes.object,
|
|
274
|
+
flashMode: PropTypes.bool,
|
|
275
|
+
finderX: PropTypes.number,
|
|
276
|
+
finderY: PropTypes.number,
|
|
277
|
+
zoom: PropTypes.number,
|
|
278
|
+
translucent: PropTypes.bool,
|
|
279
|
+
cameraType: PropTypes.string,
|
|
280
|
+
vibrate: PropTypes.bool,
|
|
281
|
+
};
|