@react-native-ohos/react-native-qr-decode-image-camera 1.1.4-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 (73) hide show
  1. package/COMMITTERS.md +7 -0
  2. package/LICENSE +21 -0
  3. package/OAT.xml +89 -0
  4. package/QrCode.podspec +14 -0
  5. package/README.OpenSource +11 -0
  6. package/README.md +13 -0
  7. package/SECURITY.md +21 -0
  8. package/harmony/qr_decode_image_camera/BuildProfile.ets +17 -0
  9. package/harmony/qr_decode_image_camera/Index.ets +8 -0
  10. package/harmony/qr_decode_image_camera/build-profile.json5 +28 -0
  11. package/harmony/qr_decode_image_camera/hvigorfile.ts +1 -0
  12. package/harmony/qr_decode_image_camera/obfuscation-rules.txt +18 -0
  13. package/harmony/qr_decode_image_camera/oh-package-lock.json5 +18 -0
  14. package/harmony/qr_decode_image_camera/oh-package.json5 +12 -0
  15. package/harmony/qr_decode_image_camera/src/main/cpp/CMakeLists.txt +9 -0
  16. package/harmony/qr_decode_image_camera/src/main/cpp/QrDecodeImageCameraPackage.h +19 -0
  17. package/harmony/qr_decode_image_camera/src/main/cpp/generated/RNOH/generated/BaseReactNativeQrDecodeImageCameraPackage.h +72 -0
  18. package/harmony/qr_decode_image_camera/src/main/cpp/generated/RNOH/generated/turbo_modules/QrDecodeImageCameraNativeModule.cpp +16 -0
  19. package/harmony/qr_decode_image_camera/src/main/cpp/generated/RNOH/generated/turbo_modules/QrDecodeImageCameraNativeModule.h +16 -0
  20. package/harmony/qr_decode_image_camera/src/main/cpp/generated/react/renderer/components/react_native_qr_decode_image_camera/ComponentDescriptors.h +24 -0
  21. package/harmony/qr_decode_image_camera/src/main/cpp/generated/react/renderer/components/react_native_qr_decode_image_camera/EventEmitters.cpp +16 -0
  22. package/harmony/qr_decode_image_camera/src/main/cpp/generated/react/renderer/components/react_native_qr_decode_image_camera/EventEmitters.h +17 -0
  23. package/harmony/qr_decode_image_camera/src/main/cpp/generated/react/renderer/components/react_native_qr_decode_image_camera/Props.cpp +19 -0
  24. package/harmony/qr_decode_image_camera/src/main/cpp/generated/react/renderer/components/react_native_qr_decode_image_camera/Props.h +18 -0
  25. package/harmony/qr_decode_image_camera/src/main/cpp/generated/react/renderer/components/react_native_qr_decode_image_camera/ShadowNodes.cpp +17 -0
  26. package/harmony/qr_decode_image_camera/src/main/cpp/generated/react/renderer/components/react_native_qr_decode_image_camera/ShadowNodes.h +23 -0
  27. package/harmony/qr_decode_image_camera/src/main/cpp/generated/react/renderer/components/react_native_qr_decode_image_camera/States.cpp +16 -0
  28. package/harmony/qr_decode_image_camera/src/main/cpp/generated/react/renderer/components/react_native_qr_decode_image_camera/States.h +19 -0
  29. package/harmony/qr_decode_image_camera/src/main/ets/Logger.ts +46 -0
  30. package/harmony/qr_decode_image_camera/src/main/ets/NativeScan.ets +150 -0
  31. package/harmony/qr_decode_image_camera/src/main/ets/RNQrDecodeImageCameraPackage.ts +29 -0
  32. package/harmony/qr_decode_image_camera/src/main/ets/RNQrDecodeImageCameraTurboModule.ts +46 -0
  33. package/harmony/qr_decode_image_camera/src/main/ets/generated/components/NativeScan.ts +125 -0
  34. package/harmony/qr_decode_image_camera/src/main/ets/generated/components/ts.ts +8 -0
  35. package/harmony/qr_decode_image_camera/src/main/ets/generated/index.ets +5 -0
  36. package/harmony/qr_decode_image_camera/src/main/ets/generated/ts.ts +6 -0
  37. package/harmony/qr_decode_image_camera/src/main/ets/generated/turboModules/QrDecodeImageCameraNativeModule.ts +16 -0
  38. package/harmony/qr_decode_image_camera/src/main/ets/generated/turboModules/ts.ts +5 -0
  39. package/harmony/qr_decode_image_camera/src/main/ets/pages/Index.ets +26 -0
  40. package/harmony/qr_decode_image_camera/src/main/ets/qr_decode_image_camera/qr_decode_image_camera.ets +47 -0
  41. package/harmony/qr_decode_image_camera/src/main/module.json5 +11 -0
  42. package/harmony/qr_decode_image_camera/src/main/resources/base/element/color.json +8 -0
  43. package/harmony/qr_decode_image_camera/src/main/resources/base/element/string.json +16 -0
  44. package/harmony/qr_decode_image_camera/src/main/resources/base/media/background.png +0 -0
  45. package/harmony/qr_decode_image_camera/src/main/resources/base/media/foreground.png +0 -0
  46. package/harmony/qr_decode_image_camera/src/main/resources/base/media/layered_image.json +7 -0
  47. package/harmony/qr_decode_image_camera/src/main/resources/base/media/startIcon.png +0 -0
  48. package/harmony/qr_decode_image_camera/src/main/resources/base/profile/main_pages.json +5 -0
  49. package/harmony/qr_decode_image_camera/src/main/resources/en_US/element/string.json +16 -0
  50. package/harmony/qr_decode_image_camera/src/main/resources/zh_CN/element/string.json +16 -0
  51. package/harmony/qr_decode_image_camera/src/mock/mock-config.json5 +2 -0
  52. package/harmony/qr_decode_image_camera/src/ohosTest/ets/test/Ability.test.ets +35 -0
  53. package/harmony/qr_decode_image_camera/src/ohosTest/ets/test/List.test.ets +5 -0
  54. package/harmony/qr_decode_image_camera/src/ohosTest/ets/testability/TestAbility.ets +47 -0
  55. package/harmony/qr_decode_image_camera/src/ohosTest/ets/testability/pages/Index.ets +17 -0
  56. package/harmony/qr_decode_image_camera/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ets +90 -0
  57. package/harmony/qr_decode_image_camera/src/ohosTest/module.json5 +36 -0
  58. package/harmony/qr_decode_image_camera/src/ohosTest/resources/base/element/color.json +8 -0
  59. package/harmony/qr_decode_image_camera/src/ohosTest/resources/base/element/string.json +16 -0
  60. package/harmony/qr_decode_image_camera/src/ohosTest/resources/base/media/icon.png +0 -0
  61. package/harmony/qr_decode_image_camera/src/ohosTest/resources/base/profile/test_pages.json +5 -0
  62. package/harmony/qr_decode_image_camera/src/test/List.test.ets +5 -0
  63. package/harmony/qr_decode_image_camera/src/test/LocalUnit.test.ets +33 -0
  64. package/harmony/qr_decode_image_camera/ts.ts +8 -0
  65. package/harmony/qr_decode_image_camera.har +0 -0
  66. package/index.js +15 -0
  67. package/package.json +39 -0
  68. package/src/Camera.tsx +58 -0
  69. package/src/NativeQrDecodeImageCamera.ts +17 -0
  70. package/src/NativeScan.ts +25 -0
  71. package/src/QRScanner.harmony.jsx +225 -0
  72. package/src/QRScanner.jsx +281 -0
  73. package/src/QRScannerView.js +381 -0
@@ -0,0 +1,47 @@
1
+ import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
2
+ import { abilityDelegatorRegistry } from '@kit.TestKit';
3
+ import { hilog } from '@kit.PerformanceAnalysisKit';
4
+ import { window } from '@kit.ArkUI';
5
+ import { Hypium } from '@ohos/hypium';
6
+ import testsuite from '../test/List.test';
7
+
8
+ export default class TestAbility extends UIAbility {
9
+ onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
10
+ hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate');
11
+ hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
12
+ hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? '');
13
+ let abilityDelegator: abilityDelegatorRegistry.AbilityDelegator;
14
+ abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator();
15
+ let abilityDelegatorArguments: abilityDelegatorRegistry.AbilityDelegatorArgs;
16
+ abilityDelegatorArguments = abilityDelegatorRegistry.getArguments();
17
+ hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!');
18
+ Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite);
19
+ }
20
+
21
+ onDestroy() {
22
+ hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy');
23
+ }
24
+
25
+ onWindowStageCreate(windowStage: window.WindowStage) {
26
+ hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate');
27
+ windowStage.loadContent('testability/pages/Index', (err) => {
28
+ if (err.code) {
29
+ hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
30
+ return;
31
+ }
32
+ hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.');
33
+ });
34
+ }
35
+
36
+ onWindowStageDestroy() {
37
+ hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy');
38
+ }
39
+
40
+ onForeground() {
41
+ hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground');
42
+ }
43
+
44
+ onBackground() {
45
+ hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground');
46
+ }
47
+ }
@@ -0,0 +1,17 @@
1
+ @Entry
2
+ @Component
3
+ struct Index {
4
+ @State message: string = 'Hello World';
5
+
6
+ build() {
7
+ Row() {
8
+ Column() {
9
+ Text(this.message)
10
+ .fontSize(50)
11
+ .fontWeight(FontWeight.Bold)
12
+ }
13
+ .width('100%')
14
+ }
15
+ .height('100%')
16
+ }
17
+ }
@@ -0,0 +1,90 @@
1
+ import { abilityDelegatorRegistry, TestRunner } from '@kit.TestKit';
2
+ import { UIAbility, Want } from '@kit.AbilityKit';
3
+ import { BusinessError } from '@kit.BasicServicesKit';
4
+ import { hilog } from '@kit.PerformanceAnalysisKit';
5
+ import { resourceManager } from '@kit.LocalizationKit';
6
+ import { util } from '@kit.ArkTS';
7
+
8
+ let abilityDelegator: abilityDelegatorRegistry.AbilityDelegator;
9
+ let abilityDelegatorArguments: abilityDelegatorRegistry.AbilityDelegatorArgs;
10
+ let jsonPath: string = 'mock/mock-config.json';
11
+ let tag: string = 'testTag';
12
+
13
+ async function onAbilityCreateCallback(data: UIAbility) {
14
+ hilog.info(0x0000, 'testTag', 'onAbilityCreateCallback, data: ${}', JSON.stringify(data));
15
+ }
16
+
17
+ async function addAbilityMonitorCallback(err: BusinessError) {
18
+ hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? '');
19
+ }
20
+
21
+ export default class OpenHarmonyTestRunner implements TestRunner {
22
+ constructor() {
23
+ }
24
+
25
+ onPrepare() {
26
+ hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare');
27
+ }
28
+
29
+ async onRun() {
30
+ let tag = 'testTag';
31
+ hilog.info(0x0000, tag, '%{public}s', 'OpenHarmonyTestRunner onRun run');
32
+ abilityDelegatorArguments = abilityDelegatorRegistry.getArguments()
33
+ abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator()
34
+ let moduleName = abilityDelegatorArguments.parameters['-m'];
35
+ let context = abilityDelegator.getAppContext().getApplicationContext().createModuleContext(moduleName);
36
+ let mResourceManager = context.resourceManager;
37
+ await checkMock(abilityDelegator, mResourceManager);
38
+ const bundleName = abilityDelegatorArguments.bundleName;
39
+ const testAbilityName: string = 'TestAbility';
40
+ let lMonitor: abilityDelegatorRegistry.AbilityMonitor = {
41
+ abilityName: testAbilityName,
42
+ onAbilityCreate: onAbilityCreateCallback,
43
+ moduleName: moduleName
44
+ };
45
+ abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
46
+ const want: Want = {
47
+ bundleName: bundleName,
48
+ abilityName: testAbilityName,
49
+ moduleName: moduleName
50
+ };
51
+ abilityDelegator.startAbility(want, (err: BusinessError, data: void) => {
52
+ hilog.info(0x0000, tag, 'startAbility : err : %{public}s', JSON.stringify(err) ?? '');
53
+ hilog.info(0x0000, tag, 'startAbility : data : %{public}s', JSON.stringify(data) ?? '');
54
+ })
55
+ hilog.info(0x0000, tag, '%{public}s', 'OpenHarmonyTestRunner onRun end');
56
+ }
57
+ }
58
+
59
+ async function checkMock(abilityDelegator: abilityDelegatorRegistry.AbilityDelegator, resourceManager: resourceManager.ResourceManager) {
60
+ let rawFile: Uint8Array;
61
+ try {
62
+ rawFile = resourceManager.getRawFileContentSync(jsonPath);
63
+ hilog.info(0x0000, tag, 'MockList file exists');
64
+ let mockStr: string = util.TextDecoder.create('utf-8', { ignoreBOM: true }).decodeWithStream(rawFile);
65
+ let mockMap: Record<string, string> = getMockList(mockStr);
66
+ try {
67
+ abilityDelegator.setMockList(mockMap)
68
+ } catch (error) {
69
+ let code = (error as BusinessError).code;
70
+ let message = (error as BusinessError).message;
71
+ hilog.error(0x0000, tag, `abilityDelegator.setMockList failed, error code: ${code}, message: ${message}.`);
72
+ }
73
+ } catch (error) {
74
+ let code = (error as BusinessError).code;
75
+ let message = (error as BusinessError).message;
76
+ hilog.error(0x0000, tag, `ResourceManager:callback getRawFileContent failed, error code: ${code}, message: ${message}.`);
77
+ }
78
+ }
79
+
80
+ function getMockList(jsonStr: string) {
81
+ let jsonObj: Record<string, Object> = JSON.parse(jsonStr);
82
+ let map: Map<string, object> = new Map<string, object>(Object.entries(jsonObj));
83
+ let mockList: Record<string, string> = {};
84
+ map.forEach((value: object, key: string) => {
85
+ let realValue: string = value['source'].toString();
86
+ mockList[key] = realValue;
87
+ });
88
+ hilog.info(0x0000, tag, '%{public}s', 'mock-json value:' + JSON.stringify(mockList) ?? '');
89
+ return mockList;
90
+ }
@@ -0,0 +1,36 @@
1
+ {
2
+ "module": {
3
+ "name": "qr_decode_image_camera_test",
4
+ "type": "feature",
5
+ "description": "$string:module_test_desc",
6
+ "mainElement": "TestAbility",
7
+ "deviceTypes": [
8
+ "2in1"
9
+ ],
10
+ "deliveryWithInstall": true,
11
+ "installationFree": false,
12
+ "pages": "$profile:test_pages",
13
+ "abilities": [
14
+ {
15
+ "name": "TestAbility",
16
+ "srcEntry": "./ets/testability/TestAbility.ets",
17
+ "description": "$string:TestAbility_desc",
18
+ "icon": "$media:icon",
19
+ "label": "$string:TestAbility_label",
20
+ "exported": true,
21
+ "startWindowIcon": "$media:icon",
22
+ "startWindowBackground": "$color:start_window_background",
23
+ "skills": [
24
+ {
25
+ "actions": [
26
+ "action.system.home"
27
+ ],
28
+ "entities": [
29
+ "entity.system.home"
30
+ ]
31
+ }
32
+ ]
33
+ }
34
+ ]
35
+ }
36
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "color": [
3
+ {
4
+ "name": "start_window_background",
5
+ "value": "#FFFFFF"
6
+ }
7
+ ]
8
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "string": [
3
+ {
4
+ "name": "module_test_desc",
5
+ "value": "test ability description"
6
+ },
7
+ {
8
+ "name": "TestAbility_desc",
9
+ "value": "the test ability"
10
+ },
11
+ {
12
+ "name": "TestAbility_label",
13
+ "value": "test label"
14
+ }
15
+ ]
16
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "src": [
3
+ "testability/pages/Index"
4
+ ]
5
+ }
@@ -0,0 +1,5 @@
1
+ import localUnitTest from './LocalUnit.test';
2
+
3
+ export default function testsuite() {
4
+ localUnitTest();
5
+ }
@@ -0,0 +1,33 @@
1
+ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
2
+
3
+ export default function localUnitTest() {
4
+ describe('localUnitTest', () => {
5
+ // Defines a test suite. Two parameters are supported: test suite name and test suite function.
6
+ beforeAll(() => {
7
+ // Presets an action, which is performed only once before all test cases of the test suite start.
8
+ // This API supports only one parameter: preset action function.
9
+ });
10
+ beforeEach(() => {
11
+ // Presets an action, which is performed before each unit test case starts.
12
+ // The number of execution times is the same as the number of test cases defined by **it**.
13
+ // This API supports only one parameter: preset action function.
14
+ });
15
+ afterEach(() => {
16
+ // Presets a clear action, which is performed after each unit test case ends.
17
+ // The number of execution times is the same as the number of test cases defined by **it**.
18
+ // This API supports only one parameter: clear action function.
19
+ });
20
+ afterAll(() => {
21
+ // Presets a clear action, which is performed after all test cases of the test suite end.
22
+ // This API supports only one parameter: clear action function.
23
+ });
24
+ it('assertContain', 0, () => {
25
+ // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
26
+ let a = 'abc';
27
+ let b = 'b';
28
+ // Defines a variety of assertion methods, which are used to declare expected boolean conditions.
29
+ expect(a).assertContain(b);
30
+ expect(a).assertEqual(a);
31
+ });
32
+ });
33
+ }
@@ -0,0 +1,8 @@
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
+ export * from './src/main/ets/RNQrDecodeImageCameraPackage';
8
+ export * from "./src/main/ets/RNQrDecodeImageCameraTurboModule";
package/index.js ADDED
@@ -0,0 +1,15 @@
1
+ import QRscanner from './src/QRScanner'
2
+ import { NativeModules } from 'react-native';
3
+ import { Platform, TurboModuleRegistry } from "react-native"
4
+ var getQr = TurboModuleRegistry ?
5
+ TurboModuleRegistry.get('QrDecodeImageCameraNativeModule') : NativeModules.QRScanReader;
6
+ const QRreader = (fileUrl) => {
7
+ if (Platform.OS == 'harmony') {
8
+ return getQr.QRreader(fileUrl)
9
+ } else {
10
+ var QRScanReader = NativeModules.QRScanReader;
11
+ return QRScanReader.readerQR(fileUrl);
12
+ }
13
+ }
14
+
15
+ export { QRscanner, QRreader }
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@react-native-ohos/react-native-qr-decode-image-camera",
3
+ "version": "1.1.4-rc.1",
4
+ "description": "Decode react native from gallery and camera",
5
+ "license": "MIT",
6
+ "main": "index.js",
7
+ "nativePackage": true,
8
+ "scripts": {
9
+ "test": "echo \"Error: no test specified\" && exit 1",
10
+ "codegen-lib": "react-native codegen-lib-harmony --no-safety-check --npm-package-name react-native-qr-decode-image-camera --cpp-output-path ./harmony/qr_decode_image_camera/src/main/cpp/generated --ets-output-path ./harmony/qr_decode_image_camera/src/main/ets/generated --turbo-modules-spec-paths ./src/NativeQrDecodeImageCamera.ts"
11
+ },
12
+ "harmony": {
13
+ "alias": "react-native-qr-decode-image-camera"
14
+ },
15
+ "keywords": [
16
+ "QRCode",
17
+ "Decode",
18
+ "scanner",
19
+ "react-native",
20
+ "harmony"
21
+ ],
22
+ "dependencies": {
23
+ "prop-types": "^15.8.1",
24
+ "react-native-qr-decode-image-camera":"^1.1.3",
25
+ "react-native": "0.72.2",
26
+ "@react-native-oh/react-native-harmony-cli": "npm:@react-native-oh/react-native-harmony-cli@^0.0.27"
27
+ },
28
+ "homepage": "https://gitcode.com/openharmony-sig/rntpc_react-native-qr-decode-image-camera#readme",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "https://gitcode.com/openharmony-sig/rntpc_react-native-qr-decode-image-camera.git"
32
+ },
33
+ "devDependencies": {
34
+ "react": "^18.2.0",
35
+ "react-native": "^0.69.0",
36
+ "react-native-vision-camera":"^4.0.1",
37
+ "react-native-qr-decode-image-camera":"^1.1.3"
38
+ }
39
+ }
package/src/Camera.tsx ADDED
@@ -0,0 +1,58 @@
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 React, { useState, useEffect } from 'react';
8
+ import {
9
+ PixelRatio
10
+ } from "react-native";
11
+ import { Camera, useCameraDevice, useCameraPermission } from 'react-native-vision-camera'
12
+ export const ComponentCamera = (props) => {
13
+ const CODE_TYPES = [
14
+ 'code-128',
15
+ 'code-39',
16
+ 'code-93',
17
+ 'codabar',
18
+ 'ean-13',
19
+ 'ean-8',
20
+ 'itf',
21
+ 'upc-e',
22
+ 'upc-a',
23
+ 'qr',
24
+ 'pdf-417',
25
+ 'aztec',
26
+ 'data-matrix'
27
+ ]
28
+ const device = useCameraDevice('back');
29
+ const { hasPermission, requestPermission } = useCameraPermission();
30
+
31
+ if (!hasPermission) {
32
+ requestPermission();
33
+ }
34
+
35
+ const codeScanner = {
36
+ codeTypes: CODE_TYPES,
37
+ onCodeScanned: (codes) => {
38
+ // console.log(`Scanned ${codes.length} codes:`, codes)
39
+ const value = codes[0]
40
+ if (value) {
41
+ props.onRead(value)
42
+ } else {
43
+ if (value == null) return
44
+ }
45
+ }
46
+ }
47
+
48
+
49
+ return (
50
+ <Camera
51
+ isActive={props.isActive}
52
+ preview={true}
53
+ device={device}
54
+ codeScanner={codeScanner}
55
+ torch={props.torch ? "on" : "off"}
56
+ />
57
+ )
58
+ }
@@ -0,0 +1,17 @@
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 type { TurboModule } from 'react-native/Libraries/TurboModule/RCTExport';
8
+ import { TurboModuleRegistry } from 'react-native';
9
+
10
+ interface IPath {
11
+ uri:string;
12
+ }
13
+ export interface Spec extends TurboModule {
14
+ QRreader: (path:IPath) => Promise<any>;
15
+ }
16
+
17
+ export default TurboModuleRegistry.get<Spec>('QrDecodeImageCameraNativeModule') as Spec | null;
@@ -0,0 +1,25 @@
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 type { ViewProps } from "react-native/Libraries/Components/View/ViewPropTypes";
8
+ import type { HostComponent } from "react-native";
9
+ import type {
10
+ BubblingEventHandler, Float, Int32,
11
+ } from 'react-native/Libraries/Types/CodegenTypes';
12
+ import codegenNativeComponent from "react-native/Libraries/Utilities/codegenNativeComponent";
13
+
14
+ type OnReadEvent = Readonly<{
15
+ result: string;
16
+ }>
17
+
18
+ export interface NativeProps extends ViewProps {
19
+ text?: string,
20
+ onRead?: BubblingEventHandler<OnReadEvent>,
21
+ flashMode?:boolean | null,
22
+ zoom?:Float,
23
+ }
24
+
25
+ export default codegenNativeComponent<NativeProps>("NativeScan") as HostComponent<NativeProps>;
@@ -0,0 +1,225 @@
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 React, { Component } from "react";
8
+ import PropTypes from "prop-types";
9
+
10
+ import {
11
+ StyleSheet,
12
+ View,
13
+ Text,
14
+ Vibration,
15
+ PixelRatio
16
+ } from "react-native";
17
+ import QRScannerView from "./QRScannerView";
18
+ import { ComponentCamera } from "./Camera";
19
+
20
+
21
+ export default class QRScannerHarmony extends Component {
22
+
23
+ constructor(props) {
24
+ super(props);
25
+ this.state = {
26
+ scanning: false,
27
+ barCodeSize: {},
28
+ isActive: true
29
+ };
30
+ }
31
+
32
+ static defaultProps = {
33
+ onRead: () => { },
34
+ renderTopView: () => { },
35
+ renderBottomView: () => (
36
+ <View style={{ flex: 1, backgroundColor: "#0000004D" }} />
37
+ ),
38
+ rectHeight: 200,
39
+ rectWidth: 200,
40
+ flashMode: false, // Flashlight mode
41
+ finderX: 0, // Viewfinder X-axis offset
42
+ finderY: 0, // Viewfinder Y-axis offset
43
+ zoom: 0.2, // Zoom range 0 - 1
44
+ translucent: false,
45
+ isRepeatScan: false,
46
+ cameraType: "back",
47
+ notAuthorizedView: () => (
48
+ <View style={styles.authorizationContainer}>
49
+ <Text style={styles.notAuthorizedText}>Camera not authorized</Text>
50
+ </View>
51
+ ),
52
+ vibrate: true,
53
+ };
54
+
55
+ render() {
56
+
57
+ return (
58
+ <View
59
+ style={{
60
+ flex: 1
61
+ }}
62
+ >
63
+ <ComponentCamera
64
+ isRepeatScan={this.props.isRepeatScan}
65
+ zoom={this.props.zoom}
66
+ torch={this.props.flashMode}
67
+ onRead={this._handleBarCodeRead}
68
+ isActive={this.state.isActive}
69
+ />
70
+ <View style={[styles.topButtonsContainer, this.props.topViewStyle]}>
71
+ {this.props.renderTopView()}
72
+ </View>
73
+ <QRScannerView
74
+ maskColor={this.props.maskColor}
75
+ cornerColor={this.props.cornerColor}
76
+ borderColor={this.props.borderColor}
77
+ rectHeight={this.props.rectHeight}
78
+ rectWidth={this.props.rectWidth}
79
+ borderWidth={this.props.borderWidth}
80
+ cornerBorderWidth={this.props.cornerBorderWidth}
81
+ cornerBorderLength={this.props.cornerBorderLength}
82
+ cornerOffsetSize={this.props.cornerOffsetSize}
83
+ isCornerOffset={this.props.isCornerOffset}
84
+ bottomHeight={this.props.bottomHeight}
85
+ scanBarAnimateTime={this.props.scanBarAnimateTime}
86
+ scanBarColor={this.props.scanBarColor}
87
+ scanBarHeight={this.props.scanBarHeight}
88
+ scanBarMargin={this.props.scanBarMargin}
89
+ hintText={this.props.hintText}
90
+ hintTextStyle={this.props.hintTextStyle}
91
+ scanBarImage={this.props.scanBarImage}
92
+ hintTextPosition={this.props.hintTextPosition}
93
+ isShowScanBar={this.props.isShowScanBar}
94
+ finderX={this.props.finderX}
95
+ finderY={this.props.finderY}
96
+ returnSize={this.barCodeSize}
97
+ />
98
+ <View
99
+ style={[styles.bottomButtonsContainer, this.props.bottomViewStyle]}
100
+ >
101
+ {this.props.renderBottomView()}
102
+ </View>
103
+
104
+ </View>
105
+ )
106
+
107
+ }
108
+
109
+ isShowCode = false;
110
+
111
+ barCodeSize = size => this.setState({ barCodeSize: size });
112
+
113
+ returnMax = (a, b) => (a > b ? a : b);
114
+
115
+ returnMin = (a, b) => (a < b ? a : b);
116
+ oldValue = null;
117
+ newValue = null;
118
+
119
+ harmonyBarCode(e) {
120
+ const { x, y, width, height } = this.state.barCodeSize;
121
+ const xInPx = PixelRatio.getPixelSizeForLayoutSize(x);
122
+ const yInPx = PixelRatio.getPixelSizeForLayoutSize(y);
123
+ const widthInPx = PixelRatio.getPixelSizeForLayoutSize(width);
124
+ const heightInPx = PixelRatio.getPixelSizeForLayoutSize(height);
125
+ const findXInPx = PixelRatio.getPixelSizeForLayoutSize(this.props.finderX);
126
+ const findYInPx = PixelRatio.getPixelSizeForLayoutSize(this.props.finderY);
127
+ let x_px = Number(e.frame.x);
128
+ let y_px = Number(e.frame.y);
129
+ let width_px = e.frame.width;
130
+ let height_px = e.frame.height;
131
+ let viewMinX = Number(xInPx - findXInPx);
132
+ let viewMinY = yInPx - findYInPx;
133
+ let viewMaxX = xInPx + widthInPx - width_px - findXInPx;
134
+ let viewMaxY = yInPx + heightInPx - height_px - findYInPx;
135
+ if (x_px > viewMinX && y_px > viewMinY && x_px < viewMaxX && y_px < viewMaxY) {
136
+ this.newValue = e.value;
137
+ if (this.props.isRepeatScan) {
138
+ if (this.newValue !== this.oldValue) {
139
+ this.oldValue = this.newValue;
140
+ this.setState({ isActive: true });
141
+ Vibration.vibrate();
142
+ this.props.onRead(e);
143
+ }
144
+ return
145
+ } else {
146
+ if (!this.isShowCode) {
147
+ this.isShowCode = true;
148
+ this.setState({ isActive: false });
149
+ Vibration.vibrate();
150
+ this.props.onRead(e);
151
+ }
152
+ }
153
+ } else {
154
+ this.newValue = null;
155
+ this.oldValue = null;
156
+ }
157
+ }
158
+
159
+
160
+ _handleBarCodeRead = e => {
161
+ this.harmonyBarCode(e);
162
+ };
163
+ }
164
+
165
+ const styles = StyleSheet.create({
166
+ topButtonsContainer: {
167
+ position: "absolute",
168
+ height: 100,
169
+ top: 0,
170
+ left: 0,
171
+ right: 0
172
+ },
173
+ bottomButtonsContainer: {
174
+ position: "absolute",
175
+ height: 100,
176
+ bottom: 0,
177
+ left: 0,
178
+ right: 0
179
+ },
180
+ authorizationContainer: {
181
+ flex: 1,
182
+ alignItems: "center",
183
+ justifyContent: "center"
184
+ },
185
+ notAuthorizedText: {
186
+ textAlign: "center",
187
+ fontSize: 16
188
+ }
189
+ });
190
+
191
+ QRScannerHarmony.propTypes = {
192
+ isRepeatScan: PropTypes.bool,
193
+ onRead: PropTypes.func,
194
+ maskColor: PropTypes.string,
195
+ borderColor: PropTypes.string,
196
+ cornerColor: PropTypes.string,
197
+ borderWidth: PropTypes.number,
198
+ cornerBorderWidth: PropTypes.number,
199
+ cornerBorderLength: PropTypes.number,
200
+ rectHeight: PropTypes.number,
201
+ rectWidth: PropTypes.number,
202
+ isCornerOffset: PropTypes.bool, //Whether the corners are offset
203
+ cornerOffsetSize: PropTypes.number,
204
+ bottomHeight: PropTypes.number,
205
+ scanBarAnimateTime: PropTypes.number,
206
+ scanBarColor: PropTypes.string,
207
+ scanBarImage: PropTypes.any,
208
+ scanBarHeight: PropTypes.number,
209
+ scanBarMargin: PropTypes.number,
210
+ hintText: PropTypes.string,
211
+ hintTextStyle: PropTypes.object,
212
+ hintTextPosition: PropTypes.number,
213
+ renderTopView: PropTypes.func,
214
+ renderBottomView: PropTypes.func,
215
+ isShowScanBar: PropTypes.bool,
216
+ topViewStyle: PropTypes.object,
217
+ bottomViewStyle: PropTypes.object,
218
+ flashMode: PropTypes.bool,
219
+ finderX: PropTypes.number,
220
+ finderY: PropTypes.number,
221
+ zoom: PropTypes.number,
222
+ translucent: PropTypes.bool,
223
+ cameraType: PropTypes.string,
224
+ vibrate: PropTypes.bool,
225
+ };