@react-native-ohos/react-native-qr-decode-image-camera 1.1.4-rc.1 → 1.1.5-rc.1

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.
Files changed (70) hide show
  1. package/.github/workflows/codeql-analysis.yml +68 -0
  2. package/COMMITTERS.md +6 -6
  3. package/LICENSE +21 -21
  4. package/OAT.xml +88 -88
  5. package/QrCode.podspec +14 -14
  6. package/README.OpenSource +10 -10
  7. package/README.md +13 -13
  8. package/SECURITY.md +21 -21
  9. package/harmony/qr_decode_image_camera/BuildProfile.ets +16 -16
  10. package/harmony/qr_decode_image_camera/Index.ets +9 -8
  11. package/harmony/qr_decode_image_camera/build-profile.json5 +27 -27
  12. package/harmony/qr_decode_image_camera/obfuscation-rules.txt +17 -17
  13. package/harmony/qr_decode_image_camera/oh-package-lock.json5 +17 -17
  14. package/harmony/qr_decode_image_camera/oh-package.json5 +12 -12
  15. package/harmony/qr_decode_image_camera/src/main/cpp/CMakeLists.txt +3 -2
  16. package/harmony/qr_decode_image_camera/src/main/cpp/QrDecodeImageCameraPackage.h +16 -10
  17. package/harmony/qr_decode_image_camera/src/main/cpp/generated/RNOH/generated/BaseReactNativeQrDecodeImageCameraPackage.h +70 -72
  18. package/harmony/qr_decode_image_camera/src/main/cpp/generated/RNOH/generated/components/NativeScanJSIBinder.h +30 -0
  19. package/harmony/qr_decode_image_camera/src/main/cpp/generated/RNOH/generated/turbo_modules/QrDecodeImageCameraNativeModule.cpp +16 -16
  20. package/harmony/qr_decode_image_camera/src/main/cpp/generated/RNOH/generated/turbo_modules/QrDecodeImageCameraNativeModule.h +16 -16
  21. package/harmony/qr_decode_image_camera/src/main/cpp/generated/react/renderer/components/react_native_qr_decode_image_camera/ComponentDescriptors.h +22 -24
  22. package/harmony/qr_decode_image_camera/src/main/cpp/generated/react/renderer/components/react_native_qr_decode_image_camera/EventEmitters.cpp +26 -16
  23. package/harmony/qr_decode_image_camera/src/main/cpp/generated/react/renderer/components/react_native_qr_decode_image_camera/EventEmitters.h +27 -17
  24. package/harmony/qr_decode_image_camera/src/main/cpp/generated/react/renderer/components/react_native_qr_decode_image_camera/Props.cpp +29 -19
  25. package/harmony/qr_decode_image_camera/src/main/cpp/generated/react/renderer/components/react_native_qr_decode_image_camera/Props.h +31 -18
  26. package/harmony/qr_decode_image_camera/src/main/cpp/generated/react/renderer/components/react_native_qr_decode_image_camera/ShadowNodes.cpp +19 -17
  27. package/harmony/qr_decode_image_camera/src/main/cpp/generated/react/renderer/components/react_native_qr_decode_image_camera/ShadowNodes.h +34 -23
  28. package/harmony/qr_decode_image_camera/src/main/cpp/generated/react/renderer/components/react_native_qr_decode_image_camera/States.cpp +18 -16
  29. package/harmony/qr_decode_image_camera/src/main/cpp/generated/react/renderer/components/react_native_qr_decode_image_camera/States.h +36 -19
  30. package/harmony/qr_decode_image_camera/src/main/ets/Logger.ts +45 -45
  31. package/harmony/qr_decode_image_camera/src/main/ets/NativeScan.ets +150 -150
  32. package/harmony/qr_decode_image_camera/src/main/ets/{RNQrDecodeImageCameraPackage.ts → RNQrDecodeImageCameraPackage.ets} +29 -28
  33. package/harmony/qr_decode_image_camera/src/main/ets/RNQrDecodeImageCameraTurboModule.ts +46 -46
  34. package/harmony/qr_decode_image_camera/src/main/ets/generated/components/NativeScan.ts +120 -125
  35. package/harmony/qr_decode_image_camera/src/main/ets/generated/components/ts.ts +5 -8
  36. package/harmony/qr_decode_image_camera/src/main/ets/generated/index.ets +5 -5
  37. package/harmony/qr_decode_image_camera/src/main/ets/generated/ts.ts +6 -6
  38. package/harmony/qr_decode_image_camera/src/main/ets/generated/turboModules/QrDecodeImageCameraNativeModule.ts +16 -16
  39. package/harmony/qr_decode_image_camera/src/main/ets/generated/turboModules/ts.ts +5 -5
  40. package/harmony/qr_decode_image_camera/src/main/ets/pages/Index.ets +25 -25
  41. package/harmony/qr_decode_image_camera/src/main/ets/qr_decode_image_camera/qr_decode_image_camera.ets +47 -47
  42. package/harmony/qr_decode_image_camera/src/main/module.json5 +10 -10
  43. package/harmony/qr_decode_image_camera/src/main/resources/base/element/color.json +7 -7
  44. package/harmony/qr_decode_image_camera/src/main/resources/base/element/string.json +15 -15
  45. package/harmony/qr_decode_image_camera/src/main/resources/base/media/layered_image.json +6 -6
  46. package/harmony/qr_decode_image_camera/src/main/resources/base/profile/main_pages.json +5 -5
  47. package/harmony/qr_decode_image_camera/src/main/resources/en_US/element/string.json +15 -15
  48. package/harmony/qr_decode_image_camera/src/main/resources/zh_CN/element/string.json +15 -15
  49. package/harmony/qr_decode_image_camera/src/mock/mock-config.json5 +1 -1
  50. package/harmony/qr_decode_image_camera/src/ohosTest/ets/test/Ability.test.ets +34 -34
  51. package/harmony/qr_decode_image_camera/src/ohosTest/ets/test/List.test.ets +4 -4
  52. package/harmony/qr_decode_image_camera/src/ohosTest/ets/testability/TestAbility.ets +46 -46
  53. package/harmony/qr_decode_image_camera/src/ohosTest/ets/testability/pages/Index.ets +16 -16
  54. package/harmony/qr_decode_image_camera/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ets +89 -89
  55. package/harmony/qr_decode_image_camera/src/ohosTest/module.json5 +36 -36
  56. package/harmony/qr_decode_image_camera/src/ohosTest/resources/base/element/color.json +7 -7
  57. package/harmony/qr_decode_image_camera/src/ohosTest/resources/base/element/string.json +15 -15
  58. package/harmony/qr_decode_image_camera/src/ohosTest/resources/base/profile/test_pages.json +5 -5
  59. package/harmony/qr_decode_image_camera/src/test/List.test.ets +4 -4
  60. package/harmony/qr_decode_image_camera/src/test/LocalUnit.test.ets +32 -32
  61. package/harmony/qr_decode_image_camera/{ts.ts → ts.ets} +7 -7
  62. package/harmony/qr_decode_image_camera.har +0 -0
  63. package/index.js +14 -14
  64. package/package.json +48 -39
  65. package/src/Camera.tsx +57 -57
  66. package/src/NativeQrDecodeImageCamera.ts +16 -16
  67. package/src/NativeScan.ts +24 -24
  68. package/src/QRScanner.harmony.jsx +225 -225
  69. package/src/QRScanner.jsx +281 -281
  70. package/src/QRScannerView.js +381 -381
@@ -1,381 +1,381 @@
1
- import React, {Component} from 'react';
2
- import {
3
- ActivityIndicator,
4
- StyleSheet,
5
- View,
6
- Animated,
7
- Easing,
8
- Text,
9
- Image,
10
- Vibration,
11
- Platform,
12
- PixelRatio,
13
- StatusBar
14
- } from 'react-native';
15
- /**
16
- * Scanning Interface Mask
17
- * Write a separate class for easy copying
18
- */
19
- export default class QRScannerView extends Component {
20
- static defaultProps = {
21
- maskColor: '#0000004D',
22
- cornerColor: '#22ff00',
23
- borderColor: '#000000',
24
- rectHeight: 200,
25
- rectWidth: 200,
26
- borderWidth: 0,
27
- cornerBorderWidth: 4,
28
- cornerBorderLength: 20,
29
- cornerOffsetSize: 1,
30
- isCornerOffset: true,
31
- bottomHeight: 100,
32
- scanBarAnimateTime: 2500,
33
- scanBarColor: '#22ff00',
34
- scanBarImage: null,
35
- scanBarHeight: 1.5,
36
- scanBarMargin: 6,
37
- hintText: 'Put the QR code / bar code into the box and it will scan automatically',
38
- hintTextStyle: {
39
- color: '#fff',
40
- fontSize: 14,
41
- backgroundColor: 'transparent'
42
- },
43
- hintTextPosition: 130,
44
- isShowScanBar: true
45
- };
46
-
47
- constructor(props) {
48
- super(props);
49
- this.state = {
50
- topWidth: 0,
51
- topHeight: 0,
52
- leftWidth: 0,
53
- animatedValue: new Animated.Value(0)
54
- }
55
- this.isClosed = false;
56
- }
57
-
58
- //Get background color
59
- getBackgroundColor = () => {
60
- return ({backgroundColor: this.props.maskColor});
61
- }
62
-
63
- //Get scan box background size
64
- getRectSize = () => {
65
- return ({height: this.props.rectHeight, width: this.props.rectWidth});
66
- }
67
-
68
- //Get scan frame border size
69
-
70
- getBorderSize = () => {
71
- if (this.props.isCornerOffset) {
72
- return ({
73
- height: this.props.rectHeight - this.props.cornerOffsetSize * 2,
74
- width: this.props.rectWidth - this.props.cornerOffsetSize * 2
75
- });
76
- } else {
77
- return ({height: this.props.rectHeight, width: this.props.rectWidth});
78
- }
79
- }
80
-
81
- //Get the color of the corner of the scan frame
82
- getCornerColor = () => {
83
- return ({borderColor: this.props.cornerColor});
84
- }
85
-
86
- //Get the size of the corner of the scan frame
87
- getCornerSize = () => {
88
- return ({height: this.props.cornerBorderLength, width: this.props.cornerBorderLength});
89
- }
90
-
91
- //Get scan frame size
92
- getBorderWidth = () => {
93
- return ({borderWidth: this.props.borderWidth});
94
- }
95
-
96
- //Get scan box color
97
- getBorderColor = () => {
98
- return ({borderColor: this.props.borderColor});
99
- }
100
-
101
- //Measure the size of the entire scanning component
102
- measureTotalSize = (e) => {
103
- let totalSize = e.layout;
104
- this.setState({topWidth: totalSize.width})
105
- }
106
-
107
- //Measure the position of the scan frame
108
- measureRectPosition = (e) => {
109
- let rectSize = e.layout;
110
- rectSize.x += this.props.finderX
111
- rectSize.y += this.props.finderY
112
- this.props.returnSize(rectSize)
113
- this.setState({topHeight: rectSize.y, leftWidth: rectSize.x})
114
- }
115
-
116
- //Get top mask height
117
- getTopMaskHeight = () => {
118
- if (this.props.isCornerOffset) {
119
- return this.state.topHeight + this.props.rectHeight - this.props.cornerOffsetSize;
120
- } else {
121
- return this.state.topHeight + this.props.rectHeight;
122
- }
123
- }
124
-
125
- //Get bottom mask height
126
- getBottomMaskHeight = () => {
127
- if (this.props.isCornerOffset) {
128
- return this.props.rectHeight + this.state.topHeight - this.props.cornerOffsetSize;
129
- } else {
130
- return this.state.topHeight + this.props.rectHeight;
131
- }
132
- }
133
-
134
- //Get the left and right mask height
135
- getSideMaskHeight = () => {
136
- if (this.props.isCornerOffset) {
137
- return this.props.rectHeight - this.props.cornerOffsetSize * 2;
138
- } else {
139
- return this.props.rectHeight;
140
- }
141
- }
142
-
143
- //Get left and right mask width
144
- getSideMaskWidth = () => {
145
- if (this.props.isCornerOffset) {
146
- return this.state.leftWidth + this.props.cornerOffsetSize;
147
- } else {
148
- return this.state.leftWidth;
149
- }
150
- }
151
-
152
- getBottomHeight = () => {
153
- return ({bottom: this.props.bottomHeight});
154
- }
155
-
156
- getScanBarMargin = () => {
157
- return ({marginRight: this.props.scanBarMargin, marginLeft: this.props.scanBarMargin})
158
- }
159
-
160
- getScanImageWidth = () => {
161
- return this.props.rectWidth - this.props.scanBarMargin * 2
162
- }
163
-
164
- //Draw scan lines
165
- _renderScanBar = () => {
166
- if (!this.props.isShowScanBar)
167
- return;
168
- if (this.props.scanBarImage) {
169
- return <Image
170
- style={{
171
- resizeMode: 'contain',
172
- width: this.getScanImageWidth(),
173
- height:this.props.scanBarHeight
174
- }}
175
- source={this.props.scanBarImage}/>
176
- } else {
177
- return <View
178
- style={[
179
- this.getScanBarMargin(), {
180
- backgroundColor: this.props.scanBarColor,
181
- height: this.props.scanBarHeight
182
- }
183
- ]}/>
184
- }
185
- }
186
-
187
- render() {
188
- const animatedStyle = {
189
- transform: [
190
- {
191
- translateY: this.state.animatedValue
192
- }
193
- ]
194
- };
195
- return (
196
- <View
197
- onLayout={({nativeEvent: e}) => this.measureTotalSize(e)}
198
- style={[
199
- styles.container, this.getBottomHeight()
200
- ]}>
201
- {/* <View style={{flex:1}}></View> */}
202
- <View
203
- style={[
204
- styles.viewfinder, this.getRectSize(),{top:this.props.finderY,left:this.props.finderX}
205
- ]}
206
- onLayout={({nativeEvent: e}) => this.measureRectPosition(e)}>
207
- <View
208
- style={[
209
- this.getBorderSize(),
210
- this.getBorderColor(),
211
- this.getBorderWidth()
212
- ]}>
213
-
214
- <Animated.View style={[animatedStyle]}>
215
- {this._renderScanBar()}
216
- </Animated.View>
217
-
218
- </View>
219
- <View
220
- style={[
221
- this.getCornerColor(),
222
- this.getCornerSize(),
223
- styles.topLeftCorner, {
224
- borderLeftWidth: this.props.cornerBorderWidth,
225
- borderTopWidth: this.props.cornerBorderWidth
226
- }
227
- ]}/>
228
- <View
229
- style={[
230
- this.getCornerColor(),
231
- this.getCornerSize(),
232
- styles.topRightCorner, {
233
- borderRightWidth: this.props.cornerBorderWidth,
234
- borderTopWidth: this.props.cornerBorderWidth
235
- }
236
- ]}/>
237
- <View
238
- style={[
239
- this.getCornerColor(),
240
- this.getCornerSize(),
241
- styles.bottomLeftCorner, {
242
- borderLeftWidth: this.props.cornerBorderWidth,
243
- borderBottomWidth: this.props.cornerBorderWidth
244
- }
245
- ]}/>
246
- <View
247
- style={[
248
- this.getCornerColor(),
249
- this.getCornerSize(),
250
- styles.bottomRightCorner, {
251
- borderRightWidth: this.props.cornerBorderWidth,
252
- borderBottomWidth: this.props.cornerBorderWidth
253
- }
254
- ]}/>
255
- </View>
256
-
257
- <View
258
- style={[
259
- this.getBackgroundColor(),
260
- styles.topMask, {
261
- bottom: this.getTopMaskHeight() - this.props.finderY * 3,
262
- top: 0,
263
- width: this.state.topWidth
264
- }
265
- ]
266
- }/>
267
-
268
- <View
269
- style={[
270
- this.getBackgroundColor(),
271
- styles.leftMask, {
272
- height: this.getSideMaskHeight(),
273
- width: this.getSideMaskWidth() - this.props.finderX ,
274
- bottom: this.getTopMaskHeight() - this.props.finderY * 3 - this.getSideMaskHeight()
275
- }
276
- ]}/>
277
-
278
- <View
279
- style={[
280
- this.getBackgroundColor(),
281
- styles.rightMask, {
282
- height: this.getSideMaskHeight(),
283
- width: this.getSideMaskWidth() - this.props.finderX * 3,
284
- bottom: this.getTopMaskHeight() - this.props.finderY * 3 - this.getSideMaskHeight()
285
- }
286
- ]}/>
287
-
288
- <View
289
- style={[
290
- this.getBackgroundColor(),
291
- styles.bottomMask, {
292
- top: this.getBottomMaskHeight() - this.props.finderY,
293
- width: this.state.topWidth
294
- }
295
- ]}/>
296
-
297
- <View
298
- style={{
299
- position: 'absolute',
300
- bottom: this.props.hintTextPosition
301
- }}>
302
- <Text style={[this.props.hintTextStyle,{top:this.props.finderY,left:this.props.finderX}]}>{this.props.hintText}</Text>
303
- </View>
304
-
305
- </View>
306
- );
307
- }
308
-
309
- componentDidMount() {
310
- this.scannerLineMove();
311
- }
312
-
313
- componentWillUnmount() {
314
- this.isClosed = true;
315
- }
316
-
317
- scannerLineMove() {
318
- if (this.isClosed) {
319
- return;
320
- }
321
- this.state.animatedValue.setValue(0); //重置Rotate动画值为0
322
- Animated.timing(
323
- this.state.animatedValue,
324
- {toValue: this.props.rectHeight,
325
- duration: this.props.scanBarAnimateTime,
326
- easing: Easing.linear,
327
- useNativeDriver: true
328
- }).start(() => this.scannerLineMove());
329
- }
330
- }
331
-
332
- const styles = StyleSheet.create({
333
- container: {
334
- alignItems: 'center',
335
- justifyContent: 'center',
336
- position: 'absolute',
337
- top: 0,
338
- right: 0,
339
- left: 0,
340
- },
341
- viewfinder: {
342
- alignItems: 'center',
343
- justifyContent: 'center'
344
- },
345
- topLeftCorner: {
346
- position: 'absolute',
347
- top: 0,
348
- left: 0
349
- },
350
- topRightCorner: {
351
- position: 'absolute',
352
- top: 0,
353
- right: 0
354
- },
355
- bottomLeftCorner: {
356
- position: 'absolute',
357
- bottom: 0,
358
- left: 0
359
- },
360
- bottomRightCorner: {
361
- position: 'absolute',
362
- bottom: 0,
363
- right: 0
364
- },
365
- topMask: {
366
- position: 'absolute',
367
- top: 0
368
- },
369
- leftMask: {
370
- position: 'absolute',
371
- left: 0
372
- },
373
- rightMask: {
374
- position: 'absolute',
375
- right: 0
376
- },
377
- bottomMask: {
378
- position: 'absolute',
379
- bottom: 0
380
- }
381
- });
1
+ import React, {Component} from 'react';
2
+ import {
3
+ ActivityIndicator,
4
+ StyleSheet,
5
+ View,
6
+ Animated,
7
+ Easing,
8
+ Text,
9
+ Image,
10
+ Vibration,
11
+ Platform,
12
+ PixelRatio,
13
+ StatusBar
14
+ } from 'react-native';
15
+ /**
16
+ * Scanning Interface Mask
17
+ * Write a separate class for easy copying
18
+ */
19
+ export default class QRScannerView extends Component {
20
+ static defaultProps = {
21
+ maskColor: '#0000004D',
22
+ cornerColor: '#22ff00',
23
+ borderColor: '#000000',
24
+ rectHeight: 200,
25
+ rectWidth: 200,
26
+ borderWidth: 0,
27
+ cornerBorderWidth: 4,
28
+ cornerBorderLength: 20,
29
+ cornerOffsetSize: 1,
30
+ isCornerOffset: true,
31
+ bottomHeight: 100,
32
+ scanBarAnimateTime: 2500,
33
+ scanBarColor: '#22ff00',
34
+ scanBarImage: null,
35
+ scanBarHeight: 1.5,
36
+ scanBarMargin: 6,
37
+ hintText: 'Put the QR code / bar code into the box and it will scan automatically',
38
+ hintTextStyle: {
39
+ color: '#fff',
40
+ fontSize: 14,
41
+ backgroundColor: 'transparent'
42
+ },
43
+ hintTextPosition: 130,
44
+ isShowScanBar: true
45
+ };
46
+
47
+ constructor(props) {
48
+ super(props);
49
+ this.state = {
50
+ topWidth: 0,
51
+ topHeight: 0,
52
+ leftWidth: 0,
53
+ animatedValue: new Animated.Value(0)
54
+ }
55
+ this.isClosed = false;
56
+ }
57
+
58
+ //Get background color
59
+ getBackgroundColor = () => {
60
+ return ({backgroundColor: this.props.maskColor});
61
+ }
62
+
63
+ //Get scan box background size
64
+ getRectSize = () => {
65
+ return ({height: this.props.rectHeight, width: this.props.rectWidth});
66
+ }
67
+
68
+ //Get scan frame border size
69
+
70
+ getBorderSize = () => {
71
+ if (this.props.isCornerOffset) {
72
+ return ({
73
+ height: this.props.rectHeight - this.props.cornerOffsetSize * 2,
74
+ width: this.props.rectWidth - this.props.cornerOffsetSize * 2
75
+ });
76
+ } else {
77
+ return ({height: this.props.rectHeight, width: this.props.rectWidth});
78
+ }
79
+ }
80
+
81
+ //Get the color of the corner of the scan frame
82
+ getCornerColor = () => {
83
+ return ({borderColor: this.props.cornerColor});
84
+ }
85
+
86
+ //Get the size of the corner of the scan frame
87
+ getCornerSize = () => {
88
+ return ({height: this.props.cornerBorderLength, width: this.props.cornerBorderLength});
89
+ }
90
+
91
+ //Get scan frame size
92
+ getBorderWidth = () => {
93
+ return ({borderWidth: this.props.borderWidth});
94
+ }
95
+
96
+ //Get scan box color
97
+ getBorderColor = () => {
98
+ return ({borderColor: this.props.borderColor});
99
+ }
100
+
101
+ //Measure the size of the entire scanning component
102
+ measureTotalSize = (e) => {
103
+ let totalSize = e.layout;
104
+ this.setState({topWidth: totalSize.width})
105
+ }
106
+
107
+ //Measure the position of the scan frame
108
+ measureRectPosition = (e) => {
109
+ let rectSize = e.layout;
110
+ rectSize.x += this.props.finderX
111
+ rectSize.y += this.props.finderY
112
+ this.props.returnSize(rectSize)
113
+ this.setState({topHeight: rectSize.y, leftWidth: rectSize.x})
114
+ }
115
+
116
+ //Get top mask height
117
+ getTopMaskHeight = () => {
118
+ if (this.props.isCornerOffset) {
119
+ return this.state.topHeight + this.props.rectHeight - this.props.cornerOffsetSize;
120
+ } else {
121
+ return this.state.topHeight + this.props.rectHeight;
122
+ }
123
+ }
124
+
125
+ //Get bottom mask height
126
+ getBottomMaskHeight = () => {
127
+ if (this.props.isCornerOffset) {
128
+ return this.props.rectHeight + this.state.topHeight - this.props.cornerOffsetSize;
129
+ } else {
130
+ return this.state.topHeight + this.props.rectHeight;
131
+ }
132
+ }
133
+
134
+ //Get the left and right mask height
135
+ getSideMaskHeight = () => {
136
+ if (this.props.isCornerOffset) {
137
+ return this.props.rectHeight - this.props.cornerOffsetSize * 2;
138
+ } else {
139
+ return this.props.rectHeight;
140
+ }
141
+ }
142
+
143
+ //Get left and right mask width
144
+ getSideMaskWidth = () => {
145
+ if (this.props.isCornerOffset) {
146
+ return this.state.leftWidth + this.props.cornerOffsetSize;
147
+ } else {
148
+ return this.state.leftWidth;
149
+ }
150
+ }
151
+
152
+ getBottomHeight = () => {
153
+ return ({bottom: this.props.bottomHeight});
154
+ }
155
+
156
+ getScanBarMargin = () => {
157
+ return ({marginRight: this.props.scanBarMargin, marginLeft: this.props.scanBarMargin})
158
+ }
159
+
160
+ getScanImageWidth = () => {
161
+ return this.props.rectWidth - this.props.scanBarMargin * 2
162
+ }
163
+
164
+ //Draw scan lines
165
+ _renderScanBar = () => {
166
+ if (!this.props.isShowScanBar)
167
+ return;
168
+ if (this.props.scanBarImage) {
169
+ return <Image
170
+ style={{
171
+ resizeMode: 'contain',
172
+ width: this.getScanImageWidth(),
173
+ height:this.props.scanBarHeight
174
+ }}
175
+ source={this.props.scanBarImage}/>
176
+ } else {
177
+ return <View
178
+ style={[
179
+ this.getScanBarMargin(), {
180
+ backgroundColor: this.props.scanBarColor,
181
+ height: this.props.scanBarHeight
182
+ }
183
+ ]}/>
184
+ }
185
+ }
186
+
187
+ render() {
188
+ const animatedStyle = {
189
+ transform: [
190
+ {
191
+ translateY: this.state.animatedValue
192
+ }
193
+ ]
194
+ };
195
+ return (
196
+ <View
197
+ onLayout={({nativeEvent: e}) => this.measureTotalSize(e)}
198
+ style={[
199
+ styles.container, this.getBottomHeight()
200
+ ]}>
201
+ {/* <View style={{flex:1}}></View> */}
202
+ <View
203
+ style={[
204
+ styles.viewfinder, this.getRectSize(),{top:this.props.finderY,left:this.props.finderX}
205
+ ]}
206
+ onLayout={({nativeEvent: e}) => this.measureRectPosition(e)}>
207
+ <View
208
+ style={[
209
+ this.getBorderSize(),
210
+ this.getBorderColor(),
211
+ this.getBorderWidth()
212
+ ]}>
213
+
214
+ <Animated.View style={[animatedStyle]}>
215
+ {this._renderScanBar()}
216
+ </Animated.View>
217
+
218
+ </View>
219
+ <View
220
+ style={[
221
+ this.getCornerColor(),
222
+ this.getCornerSize(),
223
+ styles.topLeftCorner, {
224
+ borderLeftWidth: this.props.cornerBorderWidth,
225
+ borderTopWidth: this.props.cornerBorderWidth
226
+ }
227
+ ]}/>
228
+ <View
229
+ style={[
230
+ this.getCornerColor(),
231
+ this.getCornerSize(),
232
+ styles.topRightCorner, {
233
+ borderRightWidth: this.props.cornerBorderWidth,
234
+ borderTopWidth: this.props.cornerBorderWidth
235
+ }
236
+ ]}/>
237
+ <View
238
+ style={[
239
+ this.getCornerColor(),
240
+ this.getCornerSize(),
241
+ styles.bottomLeftCorner, {
242
+ borderLeftWidth: this.props.cornerBorderWidth,
243
+ borderBottomWidth: this.props.cornerBorderWidth
244
+ }
245
+ ]}/>
246
+ <View
247
+ style={[
248
+ this.getCornerColor(),
249
+ this.getCornerSize(),
250
+ styles.bottomRightCorner, {
251
+ borderRightWidth: this.props.cornerBorderWidth,
252
+ borderBottomWidth: this.props.cornerBorderWidth
253
+ }
254
+ ]}/>
255
+ </View>
256
+
257
+ <View
258
+ style={[
259
+ this.getBackgroundColor(),
260
+ styles.topMask, {
261
+ bottom: this.getTopMaskHeight() - this.props.finderY * 3,
262
+ top: 0,
263
+ width: this.state.topWidth
264
+ }
265
+ ]
266
+ }/>
267
+
268
+ <View
269
+ style={[
270
+ this.getBackgroundColor(),
271
+ styles.leftMask, {
272
+ height: this.getSideMaskHeight(),
273
+ width: this.getSideMaskWidth() - this.props.finderX ,
274
+ bottom: this.getTopMaskHeight() - this.props.finderY * 3 - this.getSideMaskHeight()
275
+ }
276
+ ]}/>
277
+
278
+ <View
279
+ style={[
280
+ this.getBackgroundColor(),
281
+ styles.rightMask, {
282
+ height: this.getSideMaskHeight(),
283
+ width: this.getSideMaskWidth() - this.props.finderX * 3,
284
+ bottom: this.getTopMaskHeight() - this.props.finderY * 3 - this.getSideMaskHeight()
285
+ }
286
+ ]}/>
287
+
288
+ <View
289
+ style={[
290
+ this.getBackgroundColor(),
291
+ styles.bottomMask, {
292
+ top: this.getBottomMaskHeight() - this.props.finderY,
293
+ width: this.state.topWidth
294
+ }
295
+ ]}/>
296
+
297
+ <View
298
+ style={{
299
+ position: 'absolute',
300
+ bottom: this.props.hintTextPosition
301
+ }}>
302
+ <Text style={[this.props.hintTextStyle,{top:this.props.finderY,left:this.props.finderX}]}>{this.props.hintText}</Text>
303
+ </View>
304
+
305
+ </View>
306
+ );
307
+ }
308
+
309
+ componentDidMount() {
310
+ this.scannerLineMove();
311
+ }
312
+
313
+ componentWillUnmount() {
314
+ this.isClosed = true;
315
+ }
316
+
317
+ scannerLineMove() {
318
+ if (this.isClosed) {
319
+ return;
320
+ }
321
+ this.state.animatedValue.setValue(0); //重置Rotate动画值为0
322
+ Animated.timing(
323
+ this.state.animatedValue,
324
+ {toValue: this.props.rectHeight,
325
+ duration: this.props.scanBarAnimateTime,
326
+ easing: Easing.linear,
327
+ useNativeDriver: true
328
+ }).start(() => this.scannerLineMove());
329
+ }
330
+ }
331
+
332
+ const styles = StyleSheet.create({
333
+ container: {
334
+ alignItems: 'center',
335
+ justifyContent: 'center',
336
+ position: 'absolute',
337
+ top: 0,
338
+ right: 0,
339
+ left: 0,
340
+ },
341
+ viewfinder: {
342
+ alignItems: 'center',
343
+ justifyContent: 'center'
344
+ },
345
+ topLeftCorner: {
346
+ position: 'absolute',
347
+ top: 0,
348
+ left: 0
349
+ },
350
+ topRightCorner: {
351
+ position: 'absolute',
352
+ top: 0,
353
+ right: 0
354
+ },
355
+ bottomLeftCorner: {
356
+ position: 'absolute',
357
+ bottom: 0,
358
+ left: 0
359
+ },
360
+ bottomRightCorner: {
361
+ position: 'absolute',
362
+ bottom: 0,
363
+ right: 0
364
+ },
365
+ topMask: {
366
+ position: 'absolute',
367
+ top: 0
368
+ },
369
+ leftMask: {
370
+ position: 'absolute',
371
+ left: 0
372
+ },
373
+ rightMask: {
374
+ position: 'absolute',
375
+ right: 0
376
+ },
377
+ bottomMask: {
378
+ position: 'absolute',
379
+ bottom: 0
380
+ }
381
+ });