@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.
Files changed (66) 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 +7 -7
  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/generated/RNOH/generated/BaseReactNativeQrDecodeImageCameraPackage.h +72 -72
  16. package/harmony/qr_decode_image_camera/src/main/cpp/generated/RNOH/generated/turbo_modules/QrDecodeImageCameraNativeModule.cpp +16 -16
  17. package/harmony/qr_decode_image_camera/src/main/cpp/generated/RNOH/generated/turbo_modules/QrDecodeImageCameraNativeModule.h +16 -16
  18. package/harmony/qr_decode_image_camera/src/main/cpp/generated/react/renderer/components/react_native_qr_decode_image_camera/ComponentDescriptors.h +24 -24
  19. package/harmony/qr_decode_image_camera/src/main/cpp/generated/react/renderer/components/react_native_qr_decode_image_camera/EventEmitters.cpp +16 -16
  20. package/harmony/qr_decode_image_camera/src/main/cpp/generated/react/renderer/components/react_native_qr_decode_image_camera/EventEmitters.h +17 -17
  21. package/harmony/qr_decode_image_camera/src/main/cpp/generated/react/renderer/components/react_native_qr_decode_image_camera/Props.cpp +19 -19
  22. package/harmony/qr_decode_image_camera/src/main/cpp/generated/react/renderer/components/react_native_qr_decode_image_camera/Props.h +18 -18
  23. package/harmony/qr_decode_image_camera/src/main/cpp/generated/react/renderer/components/react_native_qr_decode_image_camera/ShadowNodes.cpp +17 -17
  24. package/harmony/qr_decode_image_camera/src/main/cpp/generated/react/renderer/components/react_native_qr_decode_image_camera/ShadowNodes.h +23 -23
  25. package/harmony/qr_decode_image_camera/src/main/cpp/generated/react/renderer/components/react_native_qr_decode_image_camera/States.cpp +16 -16
  26. package/harmony/qr_decode_image_camera/src/main/cpp/generated/react/renderer/components/react_native_qr_decode_image_camera/States.h +18 -18
  27. package/harmony/qr_decode_image_camera/src/main/ets/Logger.ts +45 -45
  28. package/harmony/qr_decode_image_camera/src/main/ets/NativeScan.ets +150 -150
  29. package/harmony/qr_decode_image_camera/src/main/ets/RNQrDecodeImageCameraPackage.ts +28 -28
  30. package/harmony/qr_decode_image_camera/src/main/ets/RNQrDecodeImageCameraTurboModule.ts +46 -46
  31. package/harmony/qr_decode_image_camera/src/main/ets/generated/components/NativeScan.ts +125 -125
  32. package/harmony/qr_decode_image_camera/src/main/ets/generated/components/ts.ts +8 -8
  33. package/harmony/qr_decode_image_camera/src/main/ets/generated/index.ets +5 -5
  34. package/harmony/qr_decode_image_camera/src/main/ets/generated/ts.ts +6 -6
  35. package/harmony/qr_decode_image_camera/src/main/ets/generated/turboModules/QrDecodeImageCameraNativeModule.ts +16 -16
  36. package/harmony/qr_decode_image_camera/src/main/ets/generated/turboModules/ts.ts +5 -5
  37. package/harmony/qr_decode_image_camera/src/main/ets/pages/Index.ets +25 -25
  38. package/harmony/qr_decode_image_camera/src/main/ets/qr_decode_image_camera/qr_decode_image_camera.ets +47 -47
  39. package/harmony/qr_decode_image_camera/src/main/module.json5 +10 -10
  40. package/harmony/qr_decode_image_camera/src/main/resources/base/element/color.json +7 -7
  41. package/harmony/qr_decode_image_camera/src/main/resources/base/element/string.json +15 -15
  42. package/harmony/qr_decode_image_camera/src/main/resources/base/media/layered_image.json +6 -6
  43. package/harmony/qr_decode_image_camera/src/main/resources/base/profile/main_pages.json +5 -5
  44. package/harmony/qr_decode_image_camera/src/main/resources/en_US/element/string.json +15 -15
  45. package/harmony/qr_decode_image_camera/src/main/resources/zh_CN/element/string.json +15 -15
  46. package/harmony/qr_decode_image_camera/src/mock/mock-config.json5 +1 -1
  47. package/harmony/qr_decode_image_camera/src/ohosTest/ets/test/Ability.test.ets +34 -34
  48. package/harmony/qr_decode_image_camera/src/ohosTest/ets/test/List.test.ets +4 -4
  49. package/harmony/qr_decode_image_camera/src/ohosTest/ets/testability/TestAbility.ets +46 -46
  50. package/harmony/qr_decode_image_camera/src/ohosTest/ets/testability/pages/Index.ets +16 -16
  51. package/harmony/qr_decode_image_camera/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ets +89 -89
  52. package/harmony/qr_decode_image_camera/src/ohosTest/module.json5 +36 -36
  53. package/harmony/qr_decode_image_camera/src/ohosTest/resources/base/element/color.json +7 -7
  54. package/harmony/qr_decode_image_camera/src/ohosTest/resources/base/element/string.json +15 -15
  55. package/harmony/qr_decode_image_camera/src/ohosTest/resources/base/profile/test_pages.json +5 -5
  56. package/harmony/qr_decode_image_camera/src/test/List.test.ets +4 -4
  57. package/harmony/qr_decode_image_camera/src/test/LocalUnit.test.ets +32 -32
  58. package/harmony/qr_decode_image_camera/ts.ts +7 -7
  59. package/index.js +14 -14
  60. package/package.json +39 -39
  61. package/src/Camera.tsx +57 -57
  62. package/src/NativeQrDecodeImageCamera.ts +16 -16
  63. package/src/NativeScan.ts +24 -24
  64. package/src/QRScanner.harmony.jsx +223 -225
  65. package/src/QRScanner.jsx +281 -281
  66. package/src/QRScannerView.js +382 -381
@@ -1,46 +1,46 @@
1
- /*
2
- * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3
- * Use of this source code is governed by a MIT license that can be
4
- * found in the LICENSE file.
5
- */
6
-
7
- import hilog from '@ohos.hilog';
8
-
9
- class Logger {
10
- private domain: number;
11
- private prefix: string;
12
- private format: string = '%{public}s, %{public}s';
13
- private isDebug: boolean;
14
-
15
- /**
16
- * constructor.
17
- *
18
- * @param Prefix Identifies the log tag.
19
- * @param domain Domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFFF.
20
- */
21
- constructor(prefix: string = 'blobUtil', domain: number = 0xFF00, isDebug = false) {
22
- this.prefix = prefix;
23
- this.domain = domain;
24
- this.isDebug = isDebug;
25
- }
26
-
27
- debug(...args: string[]): void {
28
- if (this.isDebug) {
29
- hilog.debug(this.domain, this.prefix, this.format, args);
30
- }
31
- }
32
-
33
- info(...args: string[]): void {
34
- hilog.info(this.domain, this.prefix, this.format, args);
35
- }
36
-
37
- warn(...args: string[]): void {
38
- hilog.warn(this.domain, this.prefix, this.format, args);
39
- }
40
-
41
- error(...args: string[]): void {
42
- hilog.error(this.domain, this.prefix, this.format, args);
43
- }
44
- }
45
-
1
+ /*
2
+ * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3
+ * Use of this source code is governed by a MIT license that can be
4
+ * found in the LICENSE file.
5
+ */
6
+
7
+ import hilog from '@ohos.hilog';
8
+
9
+ class Logger {
10
+ private domain: number;
11
+ private prefix: string;
12
+ private format: string = '%{public}s, %{public}s';
13
+ private isDebug: boolean;
14
+
15
+ /**
16
+ * constructor.
17
+ *
18
+ * @param Prefix Identifies the log tag.
19
+ * @param domain Domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFFF.
20
+ */
21
+ constructor(prefix: string = 'blobUtil', domain: number = 0xFF00, isDebug = false) {
22
+ this.prefix = prefix;
23
+ this.domain = domain;
24
+ this.isDebug = isDebug;
25
+ }
26
+
27
+ debug(...args: string[]): void {
28
+ if (this.isDebug) {
29
+ hilog.debug(this.domain, this.prefix, this.format, args);
30
+ }
31
+ }
32
+
33
+ info(...args: string[]): void {
34
+ hilog.info(this.domain, this.prefix, this.format, args);
35
+ }
36
+
37
+ warn(...args: string[]): void {
38
+ hilog.warn(this.domain, this.prefix, this.format, args);
39
+ }
40
+
41
+ error(...args: string[]): void {
42
+ hilog.error(this.domain, this.prefix, this.format, args);
43
+ }
44
+ }
45
+
46
46
  export default new Logger('RNShake', 0xFF00, false)
@@ -1,150 +1,150 @@
1
- /*
2
- * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3
- * Use of this source code is governed by a MIT license that can be
4
- * found in the LICENSE file.
5
- */
6
-
7
- import { RNOHContext ,ViewBaseProps,Descriptor} from '@rnoh/react-native-openharmony';
8
- import { RNC } from "./generated";
9
- import { scanCore, scanBarcode, customScan } from '@kit.ScanKit';
10
- import { BusinessError } from '@kit.BasicServicesKit';
11
- import { common, abilityAccessCtrl } from '@kit.AbilityKit';
12
- import { JSON } from '@kit.ArkTS';
13
- import Logger from "./Logger"
14
- interface NativeScanProps extends ViewBaseProps {
15
- text: string,
16
- flashMode: boolean,
17
- onRead:(result:string) => void,
18
- zoom:number
19
- }
20
- export type NativeScanDescriptor = Descriptor<"NativeScan", NativeScanProps>
21
- @Component
22
- export struct NativeScan {
23
- public static readonly NAME:String = RNC.NativeScan.NAME
24
- public ctx!: RNOHContext
25
- public tag: number = 0
26
- @State @Watch("changeProps") descriptor: NativeScanDescriptor = {} as NativeScanDescriptor //监听闪光灯
27
- @State userGrant: boolean = false
28
- @State surfaceId: string = ''
29
- @State isFlashLightEnable: boolean = false
30
- // 设置预览流高度,默认单位:vp
31
- @State cameraHeight: number = 200
32
- // 设置预览流宽度,默认单位:vp
33
- @State cameraWidth: number = 200
34
-
35
-
36
- private mXComponentController: XComponentController = new XComponentController()
37
- private TAG: string = '[customScanPage]';
38
- private cleanUpCallbacks: (() => void)[] = [];
39
- private eventEmitter: RNC.NativeScan.EventEmitter | undefined = undefined
40
- async showScanResult(result: Array<scanBarcode.ScanResult>) {
41
- if (result.length > 0) {
42
- // 获取到扫描结果后暂停相机流
43
- customScan.stop().then(() => {
44
- Logger.info( this.TAG, 'Succeeded in stopping customScan by promise!');
45
- }).catch((error: BusinessError) => {
46
- Logger.error( this.TAG, `Failed to stop customScan by promise. Code: ${error.code}, message: ${error.message}`);
47
- })
48
- this.onRead(JSON.stringify(result)) //返回结果
49
- }
50
- }
51
-
52
- changeProps(){
53
- //监听闪光灯
54
- if(this.descriptor.props.flashMode === true){
55
- customScan.openFlashLight();
56
- }else if (this.descriptor.props.flashMode === false){
57
- customScan.closeFlashLight();
58
- }
59
- }
60
-
61
- async reqPermissionsFromUser(): Promise<number[]> {
62
- let context = getContext() as common.UIAbilityContext;
63
- let atManager = abilityAccessCtrl.createAtManager();
64
- let grantStatus = await atManager.requestPermissionsFromUser(context, ['ohos.permission.CAMERA']);
65
- return grantStatus.authResults;
66
- }
67
-
68
- // 申请相机权限
69
- async requestCameraPermission() {
70
- let grantStatus = await this.reqPermissionsFromUser();
71
- for (let i = 0; i < grantStatus.length; i++) {
72
- if (grantStatus[i] === 0) {
73
- // 用户授权,可以继续访问目标操作
74
- this.userGrant = true;
75
-
76
- }else{
77
- Logger.info('permissions fail')
78
- }
79
- }
80
- }
81
-
82
- //扫描结果
83
- onRead(result: string){
84
- this.eventEmitter!.emit("read",{result})
85
- }
86
-
87
-
88
- build() {
89
-
90
- if(this.userGrant){
91
- XComponent({
92
- id: 'component-nativeScan',
93
- type: 'surface',
94
- controller: this.mXComponentController
95
- })
96
- .onLoad( async () => {
97
- let options: scanBarcode.ScanOptions = {
98
- scanTypes: [scanCore.ScanType.ALL],
99
- enableMultiMode: true,
100
- enableAlbum: true
101
- }
102
-
103
- // 自定义初始化接口
104
- customScan.init(options);
105
- // 获取XComponent的surfaceId
106
- let surfaceId: string = this.mXComponentController.getXComponentSurfaceId();
107
- // 设置ViewControl相应字段
108
- let viewControl: customScan.ViewControl = {
109
- width: this.cameraWidth,
110
- height: this.cameraHeight,
111
- surfaceId: surfaceId
112
- };
113
- customScan.start(viewControl).then((scanResult: Array<scanBarcode.ScanResult>) => {
114
- console.log("click``````````")
115
- Logger.info( '[Scan Sample]', `start succeeded, ${JSON.stringify(scanResult)}`,'click');
116
- this.showScanResult(scanResult);
117
- }).catch((error: BusinessError) => {
118
- Logger.info( '[Scan Sample]', `start failed, code: ${error.code}, message: ${error.message}`,'click');
119
- });
120
- if(this.descriptor.props.zoom){
121
- customScan.setZoom(this.descriptor.props.zoom)
122
- }
123
- })
124
- }
125
-
126
- }
127
- aboutToAppear() {
128
- this.requestCameraPermission();
129
- this.eventEmitter = new RNC.NativeScan.EventEmitter(this.ctx.rnInstance, this.tag)
130
- this.descriptor = this.ctx.descriptorRegistry.getDescriptor<NativeScanDescriptor>(this.tag)
131
- this.cleanUpCallbacks.push(this.ctx.descriptorRegistry.subscribeToDescriptorChanges(this.tag,
132
- (newDescriptor) => {
133
- this.descriptor = (newDescriptor as NativeScanDescriptor)
134
- }
135
- ))
136
- this.cleanUpCallbacks.push(this.ctx.componentCommandReceiver.registerCommandCallback(this.tag, (commandName) => {
137
-
138
- }))
139
- }
140
-
141
- aboutToDisappear() {
142
- this.cleanUpCallbacks.forEach(cb => cb())
143
- }
144
-
145
-
146
- }
147
-
148
-
149
-
150
-
1
+ /*
2
+ * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3
+ * Use of this source code is governed by a MIT license that can be
4
+ * found in the LICENSE file.
5
+ */
6
+
7
+ import { RNOHContext ,ViewBaseProps,Descriptor} from '@rnoh/react-native-openharmony';
8
+ import { RNC } from "./generated";
9
+ import { scanCore, scanBarcode, customScan } from '@kit.ScanKit';
10
+ import { BusinessError } from '@kit.BasicServicesKit';
11
+ import { common, abilityAccessCtrl } from '@kit.AbilityKit';
12
+ import { JSON } from '@kit.ArkTS';
13
+ import Logger from "./Logger"
14
+ interface NativeScanProps extends ViewBaseProps {
15
+ text: string,
16
+ flashMode: boolean,
17
+ onRead:(result:string) => void,
18
+ zoom:number
19
+ }
20
+ export type NativeScanDescriptor = Descriptor<"NativeScan", NativeScanProps>
21
+ @Component
22
+ export struct NativeScan {
23
+ public static readonly NAME:String = RNC.NativeScan.NAME
24
+ public ctx!: RNOHContext
25
+ public tag: number = 0
26
+ @State @Watch("changeProps") descriptor: NativeScanDescriptor = {} as NativeScanDescriptor //监听闪光灯
27
+ @State userGrant: boolean = false
28
+ @State surfaceId: string = ''
29
+ @State isFlashLightEnable: boolean = false
30
+ // 设置预览流高度,默认单位:vp
31
+ @State cameraHeight: number = 200
32
+ // 设置预览流宽度,默认单位:vp
33
+ @State cameraWidth: number = 200
34
+
35
+
36
+ private mXComponentController: XComponentController = new XComponentController()
37
+ private TAG: string = '[customScanPage]';
38
+ private cleanUpCallbacks: (() => void)[] = [];
39
+ private eventEmitter: RNC.NativeScan.EventEmitter | undefined = undefined
40
+ async showScanResult(result: Array<scanBarcode.ScanResult>) {
41
+ if (result.length > 0) {
42
+ // 获取到扫描结果后暂停相机流
43
+ customScan.stop().then(() => {
44
+ Logger.info( this.TAG, 'Succeeded in stopping customScan by promise!');
45
+ }).catch((error: BusinessError) => {
46
+ Logger.error( this.TAG, `Failed to stop customScan by promise. Code: ${error.code}, message: ${error.message}`);
47
+ })
48
+ this.onRead(JSON.stringify(result)) //返回结果
49
+ }
50
+ }
51
+
52
+ changeProps(){
53
+ //监听闪光灯
54
+ if(this.descriptor.props.flashMode === true){
55
+ customScan.openFlashLight();
56
+ }else if (this.descriptor.props.flashMode === false){
57
+ customScan.closeFlashLight();
58
+ }
59
+ }
60
+
61
+ async reqPermissionsFromUser(): Promise<number[]> {
62
+ let context = getContext() as common.UIAbilityContext;
63
+ let atManager = abilityAccessCtrl.createAtManager();
64
+ let grantStatus = await atManager.requestPermissionsFromUser(context, ['ohos.permission.CAMERA']);
65
+ return grantStatus.authResults;
66
+ }
67
+
68
+ // 申请相机权限
69
+ async requestCameraPermission() {
70
+ let grantStatus = await this.reqPermissionsFromUser();
71
+ for (let i = 0; i < grantStatus.length; i++) {
72
+ if (grantStatus[i] === 0) {
73
+ // 用户授权,可以继续访问目标操作
74
+ this.userGrant = true;
75
+
76
+ }else{
77
+ Logger.info('permissions fail')
78
+ }
79
+ }
80
+ }
81
+
82
+ //扫描结果
83
+ onRead(result: string){
84
+ this.eventEmitter!.emit("read",{result})
85
+ }
86
+
87
+
88
+ build() {
89
+
90
+ if(this.userGrant){
91
+ XComponent({
92
+ id: 'component-nativeScan',
93
+ type: 'surface',
94
+ controller: this.mXComponentController
95
+ })
96
+ .onLoad( async () => {
97
+ let options: scanBarcode.ScanOptions = {
98
+ scanTypes: [scanCore.ScanType.ALL],
99
+ enableMultiMode: true,
100
+ enableAlbum: true
101
+ }
102
+
103
+ // 自定义初始化接口
104
+ customScan.init(options);
105
+ // 获取XComponent的surfaceId
106
+ let surfaceId: string = this.mXComponentController.getXComponentSurfaceId();
107
+ // 设置ViewControl相应字段
108
+ let viewControl: customScan.ViewControl = {
109
+ width: this.cameraWidth,
110
+ height: this.cameraHeight,
111
+ surfaceId: surfaceId
112
+ };
113
+ customScan.start(viewControl).then((scanResult: Array<scanBarcode.ScanResult>) => {
114
+ console.log("click``````````")
115
+ Logger.info( '[Scan Sample]', `start succeeded, ${JSON.stringify(scanResult)}`,'click');
116
+ this.showScanResult(scanResult);
117
+ }).catch((error: BusinessError) => {
118
+ Logger.info( '[Scan Sample]', `start failed, code: ${error.code}, message: ${error.message}`,'click');
119
+ });
120
+ if(this.descriptor.props.zoom){
121
+ customScan.setZoom(this.descriptor.props.zoom)
122
+ }
123
+ })
124
+ }
125
+
126
+ }
127
+ aboutToAppear() {
128
+ this.requestCameraPermission();
129
+ this.eventEmitter = new RNC.NativeScan.EventEmitter(this.ctx.rnInstance, this.tag)
130
+ this.descriptor = this.ctx.descriptorRegistry.getDescriptor<NativeScanDescriptor>(this.tag)
131
+ this.cleanUpCallbacks.push(this.ctx.descriptorRegistry.subscribeToDescriptorChanges(this.tag,
132
+ (newDescriptor) => {
133
+ this.descriptor = (newDescriptor as NativeScanDescriptor)
134
+ }
135
+ ))
136
+ this.cleanUpCallbacks.push(this.ctx.componentCommandReceiver.registerCommandCallback(this.tag, (commandName) => {
137
+
138
+ }))
139
+ }
140
+
141
+ aboutToDisappear() {
142
+ this.cleanUpCallbacks.forEach(cb => cb())
143
+ }
144
+
145
+
146
+ }
147
+
148
+
149
+
150
+
@@ -1,29 +1,29 @@
1
- /*
2
- * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3
- * Use of this source code is governed by a MIT license that can be
4
- * found in the LICENSE file.
5
- */
6
-
7
- import { RNPackage, TurboModulesFactory } from '@rnoh/react-native-openharmony/ts';
8
- import type { TurboModule, TurboModuleContext } from '@rnoh/react-native-openharmony/ts';
9
- import { TM } from './generated/ts'
10
- import { RNQrDecodeImageCameraTurboModule } from './RNQrDecodeImageCameraTurboModule';
11
-
12
- class RNQrDecodeImageCameraTurboModuleFactory extends TurboModulesFactory {
13
- createTurboModule(name: string): TurboModule | null {
14
- if (this.hasTurboModule(name)) {
15
- return new RNQrDecodeImageCameraTurboModule(this.ctx);
16
- }
17
- return null;
18
- }
19
-
20
- hasTurboModule(name: string): boolean {
21
- return name === TM.QrDecodeImageCameraNativeModule.NAME;
22
- }
23
- }
24
-
25
- export class RNQrDecodeImageCameraPackage extends RNPackage {
26
- createTurboModulesFactory(ctx: TurboModuleContext): TurboModulesFactory {
27
- return new RNQrDecodeImageCameraTurboModuleFactory(ctx);
28
- }
1
+ /*
2
+ * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3
+ * Use of this source code is governed by a MIT license that can be
4
+ * found in the LICENSE file.
5
+ */
6
+
7
+ import { RNPackage, TurboModulesFactory } from '@rnoh/react-native-openharmony/ts';
8
+ import type { TurboModule, TurboModuleContext } from '@rnoh/react-native-openharmony/ts';
9
+ import { TM } from './generated/ts'
10
+ import { RNQrDecodeImageCameraTurboModule } from './RNQrDecodeImageCameraTurboModule';
11
+
12
+ class RNQrDecodeImageCameraTurboModuleFactory extends TurboModulesFactory {
13
+ createTurboModule(name: string): TurboModule | null {
14
+ if (this.hasTurboModule(name)) {
15
+ return new RNQrDecodeImageCameraTurboModule(this.ctx);
16
+ }
17
+ return null;
18
+ }
19
+
20
+ hasTurboModule(name: string): boolean {
21
+ return name === TM.QrDecodeImageCameraNativeModule.NAME;
22
+ }
23
+ }
24
+
25
+ export class RNQrDecodeImageCameraPackage extends RNPackage {
26
+ createTurboModulesFactory(ctx: TurboModuleContext): TurboModulesFactory {
27
+ return new RNQrDecodeImageCameraTurboModuleFactory(ctx);
28
+ }
29
29
  }
@@ -1,46 +1,46 @@
1
- /*
2
- * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3
- * Use of this source code is governed by a MIT license that can be
4
- * found in the LICENSE file.
5
- */
6
-
7
- import { TurboModule } from '@rnoh/react-native-openharmony/ts';
8
- import { TM } from './generated/ts';
9
- import window from '@ohos.window';
10
- import { scanCore, scanBarcode, detectBarcode } from '@kit.ScanKit';
11
- import { BusinessError } from '@kit.BasicServicesKit';
12
- import Logger from "./Logger"
13
-
14
- export class RNQrDecodeImageCameraTurboModule extends TurboModule implements TM.QrDecodeImageCameraNativeModule.Spec {
15
-
16
- constructor(ctx) {
17
- super(ctx);
18
- }
19
-
20
- QRreader(path: TM.QrDecodeImageCameraNativeModule.IPath): Promise<unknown> {
21
-
22
- return new Promise ((resolve,reject)=>{
23
- // 定义识码参数options
24
- let options: scanBarcode.ScanOptions = {
25
- scanTypes: [scanCore.ScanType.ALL],
26
- enableMultiMode: true,
27
- enableAlbum: true
28
- }
29
- // 调用图片识码接口
30
- detectBarcode.decode(path, options).then((result: Array<scanBarcode.ScanResult>) => {
31
- Logger.info( '[Scan Sample]', `Succeeded in getting ScanResult by promise with options, result is ${JSON.stringify(result)}`,'click success');
32
- resolve(result)
33
- }).catch((error: BusinessError) => {
34
- Logger.info( '[Scan Sample]', `Failed to get ScanResult by promise with options. Code: ${error.code}, message: ${error.message}`,"click fail");
35
- reject(error)
36
- });
37
- })
38
- }
39
-
40
- }
41
-
42
-
43
-
44
-
45
-
46
-
1
+ /*
2
+ * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3
+ * Use of this source code is governed by a MIT license that can be
4
+ * found in the LICENSE file.
5
+ */
6
+
7
+ import { TurboModule } from '@rnoh/react-native-openharmony/ts';
8
+ import { TM } from './generated/ts';
9
+ import window from '@ohos.window';
10
+ import { scanCore, scanBarcode, detectBarcode } from '@kit.ScanKit';
11
+ import { BusinessError } from '@kit.BasicServicesKit';
12
+ import Logger from "./Logger"
13
+
14
+ export class RNQrDecodeImageCameraTurboModule extends TurboModule implements TM.QrDecodeImageCameraNativeModule.Spec {
15
+
16
+ constructor(ctx) {
17
+ super(ctx);
18
+ }
19
+
20
+ QRreader(path: TM.QrDecodeImageCameraNativeModule.IPath): Promise<unknown> {
21
+
22
+ return new Promise ((resolve,reject)=>{
23
+ // 定义识码参数options
24
+ let options: scanBarcode.ScanOptions = {
25
+ scanTypes: [scanCore.ScanType.ALL],
26
+ enableMultiMode: true,
27
+ enableAlbum: true
28
+ }
29
+ // 调用图片识码接口
30
+ detectBarcode.decode(path, options).then((result: Array<scanBarcode.ScanResult>) => {
31
+ Logger.info( '[Scan Sample]', `Succeeded in getting ScanResult by promise with options, result is ${JSON.stringify(result)}`,'click success');
32
+ resolve(result)
33
+ }).catch((error: BusinessError) => {
34
+ Logger.info( '[Scan Sample]', `Failed to get ScanResult by promise with options. Code: ${error.code}, message: ${error.message}`,"click fail");
35
+ reject(error)
36
+ });
37
+ })
38
+ }
39
+
40
+ }
41
+
42
+
43
+
44
+
45
+
46
+