dynamsoft-capture-vision-react-native 2.6.1002 → 2.6.1013

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 (119) hide show
  1. package/README.md +7 -5
  2. package/android/.gitignore +4 -0
  3. package/android/build.gradle +29 -28
  4. package/android/src/main/java/com/dynamsoft/reactnativelib/ReactNativeDcvPackage.kt +15 -1
  5. package/android/src/main/java/com/dynamsoft/reactnativelib/dce/CameraEnhancerModuleImpl.kt +0 -1
  6. package/android/src/main/java/com/dynamsoft/reactnativelib/dce/CameraLifeCycleOwner.java +14 -0
  7. package/android/src/main/java/com/dynamsoft/reactnativelib/dce/ImageEditorViewModuleImpl.kt +3 -2
  8. package/android/src/main/java/com/dynamsoft/reactnativelib/rtu/BarcodeScannerModuleImpl.kt +80 -0
  9. package/android/src/main/java/com/dynamsoft/reactnativelib/rtu/MRZScannerModuleImpl.kt +77 -0
  10. package/android/src/main/java/com/dynamsoft/reactnativelib/rtu/ScannerInterface.kt +47 -0
  11. package/android/src/main/jniLibs/arm64-v8a/librn_dys.so +0 -0
  12. package/android/src/main/jniLibs/armeabi-v7a/librn_dys.so +0 -0
  13. package/android/src/main/jniLibs/x86/librn_dys.so +0 -0
  14. package/android/src/main/jniLibs/x86_64/librn_dys.so +0 -0
  15. package/android/src/newarch/com/dynamsoft/reactnativelib/BarcodeScannerModule.kt +22 -0
  16. package/android/src/newarch/com/dynamsoft/reactnativelib/MRZScannerModule.kt +22 -0
  17. package/android/src/oldarch/com/dynamsoft/reactnativelib/BarcodeScannerModule.kt +24 -0
  18. package/android/src/oldarch/com/dynamsoft/reactnativelib/MRZScannerModule.kt +24 -0
  19. package/dynamsoft-capture-vision-react-native.podspec +4 -2
  20. package/ios/CPP/RNDynamsoft+Json.h +2 -0
  21. package/ios/CPP/RNDynamsoft+Json.m +9 -0
  22. package/ios/RNDynamsoftBarcodeScanner.h +14 -0
  23. package/ios/RNDynamsoftBarcodeScanner.m +169 -0
  24. package/ios/RNDynamsoftCaptureVisionRouter.mm +14 -6
  25. package/ios/RNDynamsoftMRZScanner.h +14 -0
  26. package/ios/RNDynamsoftMRZScanner.m +140 -0
  27. package/package.json +4 -4
  28. package/src/core/CoreModule.tsx +1 -0
  29. package/src/core/DSRect.tsx +3 -4
  30. package/src/core/EnumCaptureResultItemType.tsx +12 -5
  31. package/src/core/EnumColourChannelUsageType.tsx +2 -2
  32. package/src/core/EnumCrossVerificationStatus.tsx +8 -5
  33. package/src/core/EnumGrayscaleEnhancementMode.tsx +5 -1
  34. package/src/core/EnumGrayscaleTransformationMode.tsx +6 -2
  35. package/src/core/EnumPixelFormat.tsx +1 -1
  36. package/src/core/ImageData.tsx +9 -8
  37. package/src/core/ImageSourceAdapter.tsx +5 -2
  38. package/src/core/Point.tsx +1 -1
  39. package/src/core/index.tsx +1 -2
  40. package/src/cvr/CaptureVisionRouter.tsx +40 -36
  41. package/src/cvr/CaptureVisionRouterModule.tsx +1 -0
  42. package/src/cvr/CapturedResult.tsx +2 -2
  43. package/src/cvr/CapturedResultFilter.tsx +3 -1
  44. package/src/cvr/CapturedResultReceiver.tsx +9 -9
  45. package/src/cvr/SimplifiedCaptureVisionSettings.tsx +2 -2
  46. package/src/dbr/BarcodeReaderModule.tsx +1 -0
  47. package/src/dbr/BarcodeResultItem.tsx +5 -6
  48. package/src/dbr/DecodedBarcodesResult.tsx +3 -2
  49. package/src/dbr/EnumBarcodeFormat.tsx +10 -9
  50. package/src/dbr/EnumDeblurMode.tsx +1 -1
  51. package/src/dbr/EnumLocalizationMode.tsx +1 -1
  52. package/src/dbr/SimplifiedBarcodeReaderSettings.tsx +5 -5
  53. package/src/dce/CameraEnhancer.tsx +18 -17
  54. package/src/dce/CameraEnhancerModule.tsx +1 -0
  55. package/src/dce/CameraView.tsx +3 -3
  56. package/src/dce/DynamsoftCameraViewNativeComponent.ts +4 -1
  57. package/src/dce/EnumCameraPosition.tsx +1 -1
  58. package/src/dce/FeedBack.tsx +1 -0
  59. package/src/dce/ImageEditorView.tsx +3 -2
  60. package/src/dce/index.tsx +2 -1
  61. package/src/dcp/CodeParserDedicatorModule.tsx +1 -0
  62. package/src/dcp/CodeParserModule.tsx +1 -0
  63. package/src/dcp/EnumMappingStatus.tsx +1 -1
  64. package/src/dcp/EnumValidationStatus.tsx +1 -1
  65. package/src/dcp/ParsedResult.tsx +4 -3
  66. package/src/dcp/ParsedResultItem.tsx +4 -4
  67. package/src/ddn/DetectedQuadResultItem.tsx +9 -10
  68. package/src/ddn/DetectedQuadsResult.tsx +4 -1
  69. package/src/ddn/DocumentNormalizerModule.tsx +1 -0
  70. package/src/ddn/EnumImageColourMode.tsx +1 -1
  71. package/src/ddn/NormalizedImageResultItem.tsx +10 -11
  72. package/src/ddn/NormalizedImagesResult.tsx +4 -1
  73. package/src/ddn/SimplifiedDocumentNormalizerSettings.tsx +6 -6
  74. package/src/dip/ImageProcessingModule.tsx +1 -0
  75. package/src/dlr/LabelRecognizerModule.tsx +1 -0
  76. package/src/dlr/RecognizedTextLinesResult.tsx +5 -3
  77. package/src/dlr/SimplifiedLabelRecognizerSettings.tsx +1 -2
  78. package/src/dlr/TextLineResultItem.tsx +4 -5
  79. package/src/index.tsx +1 -0
  80. package/src/license/LicenseManager.tsx +3 -2
  81. package/src/license/LicenseModule.tsx +1 -0
  82. package/src/rtu/BarcodeScanConfig.tsx +104 -0
  83. package/src/rtu/BarcodeScanResult.tsx +31 -0
  84. package/src/rtu/BarcodeScanner.tsx +112 -0
  85. package/src/rtu/EnumResultState.tsx +21 -0
  86. package/src/rtu/MRZScanConfig.tsx +67 -0
  87. package/src/rtu/MRZScanResult.tsx +84 -0
  88. package/src/rtu/MRZScanner.tsx +90 -0
  89. package/src/rtu/NativeDynamsoftBarcodeScannerModule.tsx +6 -0
  90. package/src/rtu/NativeDynamsoftMRZScannerModule.tsx +6 -0
  91. package/src/rtu/index.tsx +7 -0
  92. package/src/utility/MultiFrameResultCrossFilter.tsx +12 -12
  93. package/src/utility/UtilityModule.tsx +1 -0
  94. package/android/CMakeLists.txt +0 -14
  95. package/android/src/main/cpp/MutableRawBuffer.cpp +0 -24
  96. package/android/src/main/cpp/MutableRawBuffer.h +0 -24
  97. package/android/src/main/cpp/android_log.h +0 -14
  98. package/android/src/main/cpp/core/ImageDataHostObject.cpp +0 -95
  99. package/android/src/main/cpp/core/ImageDataHostObject.h +0 -34
  100. package/android/src/main/cpp/core/JsiCore.cpp +0 -284
  101. package/android/src/main/cpp/core/JsiCore.h +0 -51
  102. package/android/src/main/cpp/cvr/JsiCvr.cpp +0 -263
  103. package/android/src/main/cpp/cvr/JsiCvr.h +0 -51
  104. package/android/src/main/cpp/dbr/JsiDbr.cpp +0 -38
  105. package/android/src/main/cpp/dbr/JsiDbr.h +0 -26
  106. package/android/src/main/cpp/dce/JsiDce.cpp +0 -59
  107. package/android/src/main/cpp/dce/JsiDce.h +0 -17
  108. package/android/src/main/cpp/dcp/JsiDcp.cpp +0 -51
  109. package/android/src/main/cpp/dcp/JsiDcp.h +0 -31
  110. package/android/src/main/cpp/ddn/JsiDdn.cpp +0 -34
  111. package/android/src/main/cpp/ddn/JsiDdn.h +0 -27
  112. package/android/src/main/cpp/dlr/JsiDlr.cpp +0 -51
  113. package/android/src/main/cpp/dlr/JsiDlr.h +0 -26
  114. package/android/src/main/cpp/utility/JsiUtility.cpp +0 -151
  115. package/android/src/main/cpp/utility/JsiUtility.h +0 -15
  116. package/android/src/main/java/com/dynamsoft/reactnativelib/dce/CameraLifeCycleOwner.kt +0 -9
  117. package/src/core/CompletionListener.tsx +0 -5
  118. package/src/core/Rect.tsx +0 -21
  119. package/src/dce/TorchButton.tsx +0 -23
package/README.md CHANGED
@@ -41,18 +41,20 @@ DCV enables you to develop highly customizable applications for barcode reading,
41
41
  - Node: 18 or higher
42
42
 
43
43
  ## User Guide
44
-
45
- - [Barcode Reader Integration Guide](https://github.com/Dynamsoft/capture-vision-react-native-samples/blob/main/ScanSingleBarcode/barcode-reader-integration-guide.md)
46
- - [Document Scanner Integration Guide](https://github.com/Dynamsoft/capture-vision-react-native-samples/blob/main/DetectAndDeskewDocument/document-scanner-integration-guide.md)
47
- - [MRZ Scanner Integration Guide](https://github.com/Dynamsoft/capture-vision-react-native-samples/blob/main/ScanMRZ/mrz-scanner-integration-guide.md)
44
+ - [Foundation Barcode Reader Integration Guide](https://github.com/Dynamsoft/capture-vision-react-native-samples/blob/main/foundation-barcode-reader-guide.md)
45
+ - [Ready-to-use Barcode Scanner Integration Guide](https://github.com/Dynamsoft/capture-vision-react-native-samples/blob/main/ready-to-use-barcode-scanner-guide.md)
46
+ - [Document Scanner Integration Guide](https://github.com/Dynamsoft/capture-vision-react-native-samples/blob/main/document-scanner-guide.md)
47
+ - [MRZ Scanner Integration Guide](https://github.com/Dynamsoft/capture-vision-react-native-samples/blob/main/mrz-scanner-guide.md)
48
+ - [Divers' License Scanner Integration Guide](https://github.com/Dynamsoft/capture-vision-react-native-samples/blob/main/drivers-license-scanner-guide.md)
48
49
 
49
50
  ## Samples
50
51
 
51
52
  You can view all the DCV React Native samples via the following links:
52
53
 
53
- - [ScanSingleBarcode](https://github.com/Dynamsoft/capture-vision-react-native-samples/tree/main/ScanSingleBarcode)
54
+ - [ScanBarcodes](https://github.com/Dynamsoft/capture-vision-react-native-samples/tree/main/ScanBarcodes)
54
55
  - [DetectAndDeskewDocument](https://github.com/Dynamsoft/capture-vision-react-native-samples/tree/main/DetectAndDeskewDocument)
55
56
  - [ScanMRZ](https://github.com/Dynamsoft/capture-vision-react-native-samples/tree/main/ScanMRZ)
57
+ - [ReadDriverLicense](https://github.com/Dynamsoft/capture-vision-react-native-samples/tree/main/ReadDriverLicense)
56
58
 
57
59
  ## License
58
60
 
@@ -0,0 +1,4 @@
1
+ build
2
+ .cxx
3
+ .idea
4
+ .gradle
@@ -59,40 +59,39 @@ android {
59
59
  targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
60
60
  versionCode 1
61
61
  versionName "1.0"
62
- externalNativeBuild {
63
- cmake {
62
+ // externalNativeBuild {
63
+ // cmake {
64
64
  // cppFlags "-O2 -frtti -fexceptions -Wall -Wno-unused-variable -fstack-protector-all"
65
- arguments "-DANDROID_STL=c++_shared"
66
- }
67
- }
65
+ // arguments "-DANDROID_STL=c++_shared"
66
+ // }
67
+ // }
68
68
  buildConfigField("boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled.toString())
69
69
  }
70
70
  lintOptions {
71
71
  abortOnError false
72
72
  }
73
- externalNativeBuild {
74
- cmake {
75
- path file('CMakeLists.txt')
76
- version '3.18.1'
77
- }
78
- }
79
-
80
- buildFeatures {
81
- prefab true
82
- }
83
- packagingOptions {
84
- // doNotStrip resolveBuildType() == 'debug' ? "**/**/*.so" : ''
85
- excludes = [
86
- "META-INF",
87
- "META-INF/**",
88
- "**/libjsi.so",
89
- "**/libc++_shared.so"
90
- ]
91
- }
73
+ // externalNativeBuild {
74
+ // cmake {
75
+ // path file('CMakeLists.txt')
76
+ // version '3.18.1'
77
+ // }
78
+ // }
79
+
80
+ // buildFeatures {
81
+ // prefab true
82
+ // }
83
+
84
+ // packagingOptions {
85
+ // excludes = [
86
+ // "META-INF",
87
+ // "META-INF/**",
88
+ // "**/libjsi.so",
89
+ // "**/libc++_shared.so"
90
+ // ]
91
+ // }
92
92
  }
93
93
 
94
94
  repositories {
95
- // ref: https://www.baeldung.com/maven-local-repository
96
95
  google()
97
96
  mavenCentral()
98
97
  maven {
@@ -117,13 +116,15 @@ dependencies {
117
116
  def kotlinVersion = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["kotlinVersion"]
118
117
 
119
118
  //noinspection GradleDynamicVersion
120
- implementation 'com.facebook.react:react-native:+' // From node_modules
121
- // compileOnly "com.facebook.react:react-android:0.75.2"
119
+ implementation 'com.facebook.react:react-native:+'
120
+ compileOnly "com.facebook.react:react-android:+"
122
121
 
123
122
  //noinspection GradleDependency
124
123
 
125
124
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
126
125
  implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3"
127
126
 
128
- implementation "com.dynamsoft:dynamsoftcapturevisionbundle:2.6.1002"
127
+ implementation "com.dynamsoft:dynamsoftcapturevisionbundle:2.6.1003"
128
+ implementation( "com.dynamsoft:dynamsoftbarcodereaderbundle:10.4.3002@aar")
129
+ implementation ('com.dynamsoft:mrzscannerbundle:2.0.1@aar')
129
130
  }
@@ -6,6 +6,8 @@ import com.dynamsoft.reactnativelib.cvr.CaptureVisionRouterModuleImpl
6
6
  import com.dynamsoft.reactnativelib.dce.CameraEnhancerModuleImpl
7
7
  import com.dynamsoft.reactnativelib.dce.ImageEditorViewModuleImpl
8
8
  import com.dynamsoft.reactnativelib.license.LicenseModuleImpl
9
+ import com.dynamsoft.reactnativelib.rtu.BarcodeScannerModuleImpl
10
+ import com.dynamsoft.reactnativelib.rtu.MRZScannerModuleImpl
9
11
  import com.dynamsoft.reactnativelib.utility.ImageManagerModuleImpl
10
12
  import com.dynamsoft.reactnativelib.utility.MultiCrossFilterModuleImpl
11
13
  import com.facebook.react.TurboReactPackage
@@ -18,7 +20,7 @@ import com.facebook.react.uimanager.ViewManager
18
20
  class ReactNativeDcvPackage : TurboReactPackage() {
19
21
  companion object {
20
22
  init {
21
- System.loadLibrary("react-native-dcv-android")
23
+ System.loadLibrary("rn_dys")
22
24
  }
23
25
  }
24
26
 
@@ -36,6 +38,8 @@ class ReactNativeDcvPackage : TurboReactPackage() {
36
38
  VersionsModule.NAME -> VersionsModule(context)
37
39
  ImageEditorViewModuleImpl.NAME -> ImageEditorViewModule(context)
38
40
  ImageManagerModuleImpl.NAME -> ImageManagerModule(context)
41
+ BarcodeScannerModuleImpl.NAME -> BarcodeScannerModule(context)
42
+ MRZScannerModuleImpl.NAME -> MRZScannerModule(context)
39
43
  else -> null
40
44
  }
41
45
  }
@@ -83,6 +87,16 @@ class ReactNativeDcvPackage : TurboReactPackage() {
83
87
  ImageManagerModuleImpl.NAME,
84
88
  ImageManagerModuleImpl.NAME,
85
89
  false, false, true, false, isEnableNewArch
90
+ ),
91
+ BarcodeScannerModuleImpl.NAME to ReactModuleInfo(
92
+ BarcodeScannerModuleImpl.NAME,
93
+ BarcodeScannerModuleImpl.NAME,
94
+ false, false, true, false, isEnableNewArch
95
+ ),
96
+ MRZScannerModuleImpl.NAME to ReactModuleInfo(
97
+ MRZScannerModuleImpl.NAME,
98
+ MRZScannerModuleImpl.NAME,
99
+ false, false, true, false, isEnableNewArch
86
100
  )
87
101
  )
88
102
  }
@@ -9,7 +9,6 @@ import com.dynamsoft.dce.EnumCameraPosition
9
9
  import com.dynamsoft.dce.EnumFocusMode
10
10
  import com.dynamsoft.dce.Feedback
11
11
  import com.dynamsoft.dce.utils.PermissionUtil
12
- import com.dynamsoft.reactnative.dce.utils.CameraLifeCycleOwner
13
12
  import com.dynamsoft.reactnativelib.core.ImageSourceAdapterModuleImpl.Companion.mapISA
14
13
  import com.dynamsoft.reactnativelib.utils.toScanRegion
15
14
  import com.dynamsoft.reactnativelib.utils.toWritableMap
@@ -0,0 +1,14 @@
1
+ package com.dynamsoft.reactnativelib.dce;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import androidx.lifecycle.LifecycleOwner;
5
+ import androidx.lifecycle.LifecycleRegistry;
6
+
7
+ public class CameraLifeCycleOwner implements LifecycleOwner {
8
+ private final LifecycleRegistry lifecycleRegistry = new LifecycleRegistry(this);
9
+ @NonNull
10
+ @Override
11
+ public LifecycleRegistry getLifecycle() {
12
+ return lifecycleRegistry;
13
+ }
14
+ }
@@ -13,7 +13,6 @@ import com.facebook.react.bridge.Promise
13
13
  import com.facebook.react.bridge.ReactApplicationContext
14
14
  import com.facebook.react.bridge.ReactMethod
15
15
  import com.facebook.react.bridge.ReadableArray
16
- import com.facebook.react.uimanager.IllegalViewOperationException
17
16
  import com.facebook.react.uimanager.UIManagerHelper
18
17
  import kotlinx.coroutines.CoroutineName
19
18
  import kotlinx.coroutines.CoroutineScope
@@ -42,7 +41,9 @@ class ImageEditorViewModuleImpl(private val reactContext: ReactApplicationContex
42
41
  }
43
42
  val drawingItems = ArrayList<DrawingItem<*>>()
44
43
  for (i in 0 until readableArray.size()) {
45
- drawingItems.add(QuadDrawingItem(readableArray.getMap(i).toQuad()))
44
+ readableArray.getMap(i)?.toQuad()?.apply {
45
+ drawingItems.add(QuadDrawingItem(this))
46
+ }
46
47
  }
47
48
  imageEditorView.getDrawingLayer(layerId).drawingItems = drawingItems
48
49
  promise.resolve(null)
@@ -0,0 +1,80 @@
1
+ package com.dynamsoft.reactnativelib.rtu
2
+
3
+ import android.app.Activity
4
+ import android.content.Intent
5
+ import com.dynamsoft.dbr.EnumBarcodeFormat
6
+ import com.dynamsoft.dbrbundle.ui.BarcodeScanResult
7
+ import com.dynamsoft.dbrbundle.ui.BarcodeScannerActivity
8
+ import com.dynamsoft.dbrbundle.ui.BarcodeScannerConfig
9
+ import com.dynamsoft.reactnative.basicutils.toWritableArray
10
+ import com.dynamsoft.reactnativelib.utils.toScanRegion
11
+ import com.facebook.react.bridge.Arguments
12
+ import com.facebook.react.bridge.Promise
13
+ import com.facebook.react.bridge.ReactApplicationContext
14
+ import com.facebook.react.bridge.ReadableMap
15
+ import com.facebook.react.bridge.WritableMap
16
+
17
+
18
+ class BarcodeScannerModuleImpl(private val reactContext: ReactApplicationContext): ScannerModule(reactContext) {
19
+ companion object {
20
+ const val NAME = "DynamsoftBarcodeScannerModule"
21
+ }
22
+
23
+ fun startBarcodeScanner(config: ReadableMap, promise: Promise) {
24
+ super.startScanner(config, promise)
25
+ }
26
+
27
+ fun closeBarcodeScanner(promise: Promise) {
28
+ super.closeScanner(promise)
29
+ }
30
+ override fun createIntent(config: ReadableMap) =
31
+ BarcodeScannerActivity.ResultContract().createIntent(reactContext, config.toBarcodeScannerConfig())
32
+
33
+ override fun getPromiseResolve(intent: Intent) = BarcodeScanResult(Activity.RESULT_OK, intent).toWritableMap()
34
+
35
+ private fun ReadableMap.toBarcodeScannerConfig() = BarcodeScannerConfig().also {
36
+ it.license = getString("license")
37
+ it.barcodeFormats = (getString("_barcodeFormatNumberString") ?: EnumBarcodeFormat.BF_DEFAULT.toString()).toULong().toLong()
38
+ // it.templateFilePath = getString("templateFilePath")
39
+ if(hasKey("scanRegion")) {
40
+ it.scanRegion = getMap("scanRegion")?.toScanRegion()
41
+ }
42
+ if (hasKey("isTorchButtonVisible")) {
43
+ it.isTorchButtonVisible = getBoolean("isTorchButtonVisible")
44
+ }
45
+ if (hasKey("isBeepEnabled")) {
46
+ it.isBeepEnabled = getBoolean("isBeepEnabled")
47
+ }
48
+ if (hasKey("isAutoZoomEnabled")) {
49
+ it.isAutoZoomEnabled = getBoolean("isAutoZoomEnabled")
50
+ }
51
+ if (hasKey("isCloseButtonVisible")) {
52
+ it.isCloseButtonVisible = getBoolean("isCloseButtonVisible")
53
+ }
54
+ if (hasKey("isScanLaserVisible")) {
55
+ it.isScanLaserVisible = getBoolean("isScanLaserVisible")
56
+ }
57
+ if(hasKey("maxConsecutiveStableFramesToExit")) {
58
+ it.maxConsecutiveStableFramesToExit = getInt("maxConsecutiveStableFramesToExit")
59
+ }
60
+ if(hasKey("scanningMode")) {
61
+ it.scanningMode = getInt("scanningMode")
62
+ }
63
+ if(hasKey("expectedBarcodesCount")) {
64
+ it.expectedBarcodesCount = getInt("expectedBarcodesCount")
65
+ }
66
+ if(hasKey("templateFile")) {
67
+ it.templateFile = getString("templateFile")
68
+ }
69
+ if(hasKey("isCameraToggleButtonVisible")) {
70
+ it.isCameraToggleButtonVisible = getBoolean("isCameraToggleButtonVisible")
71
+ }
72
+ }
73
+
74
+ private fun BarcodeScanResult.toWritableMap(): WritableMap = Arguments.createMap().apply {
75
+ putInt("resultStatus", resultStatus)
76
+ putInt("errorCode", errorCode)
77
+ putString("errorString", errorString)
78
+ putArray("barcodes", barcodes?.toWritableArray())
79
+ }
80
+ }
@@ -0,0 +1,77 @@
1
+ package com.dynamsoft.reactnativelib.rtu
2
+
3
+ import android.app.Activity
4
+ import android.content.Intent
5
+ import com.dynamsoft.mrzscannerbundle.ui.EnumDocumentType
6
+ import com.dynamsoft.mrzscannerbundle.ui.MRZData
7
+ import com.dynamsoft.mrzscannerbundle.ui.MRZScanResult
8
+ import com.dynamsoft.mrzscannerbundle.ui.MRZScannerActivity
9
+ import com.dynamsoft.mrzscannerbundle.ui.MRZScannerConfig
10
+ import com.facebook.react.bridge.Arguments
11
+ import com.facebook.react.bridge.Promise
12
+ import com.facebook.react.bridge.ReactApplicationContext
13
+ import com.facebook.react.bridge.ReadableMap
14
+ import com.facebook.react.bridge.WritableMap
15
+
16
+
17
+ class MRZScannerModuleImpl(private val reactContext: ReactApplicationContext): ScannerModule(reactContext) {
18
+ companion object {
19
+ const val NAME = "DynamsoftMRZScannerModule"
20
+ }
21
+
22
+ fun startMRZScanner(config: ReadableMap, promise: Promise) {
23
+ super.startScanner(config, promise)
24
+ }
25
+
26
+ fun closeMRZScanner(promise: Promise) {
27
+ super.closeScanner(promise)
28
+ }
29
+
30
+ override fun createIntent(config: ReadableMap) =
31
+ MRZScannerActivity.ResultContract().createIntent(reactContext, config.toMRZScannerConfig())
32
+
33
+ override fun getPromiseResolve(intent: Intent) = MRZScanResult(Activity.RESULT_OK, intent).toWritableMap()
34
+
35
+ private fun ReadableMap.toMRZScannerConfig() = MRZScannerConfig().also {
36
+ it.license = getString("license")
37
+ if (hasKey("isTorchButtonVisible")) {
38
+ it.isTorchButtonVisible = getBoolean("isTorchButtonVisible")
39
+ }
40
+ if (hasKey("isBeepEnabled")) {
41
+ it.isBeepEnabled = getBoolean("isBeepEnabled")
42
+ }
43
+ if (hasKey("isCloseButtonVisible")) {
44
+ it.isCloseButtonVisible = getBoolean("isCloseButtonVisible")
45
+ }
46
+ if (hasKey("isGuideFrameVisible")) {
47
+ it.isGuideFrameVisible = getBoolean("isGuideFrameVisible")
48
+ }
49
+ if (hasKey("documentType")) {
50
+ it.documentType = EnumDocumentType.values()[getInt("documentType")]
51
+ }
52
+ if(hasKey("templateFile")) {
53
+ it.templateFile = getString("templateFile")
54
+ }
55
+ }
56
+
57
+ private fun MRZScanResult.toWritableMap(): WritableMap = Arguments.createMap().apply {
58
+ putInt("resultStatus", resultStatus)
59
+ putInt("errorCode", errorCode)
60
+ putString("errorString", errorString)
61
+ putMap("data", data.toWritableMap())
62
+ }
63
+
64
+ private fun MRZData.toWritableMap() = Arguments.createMap().apply {
65
+ putString("documentType", documentType)
66
+ putString("firstName", firstName)
67
+ putString("lastName", lastName)
68
+ putString("sex", sex)
69
+ putString("issuingState", issuingState)
70
+ putString("nationality", nationality)
71
+ putString("dateOfBirth", dateOfBirth)
72
+ putString("dateOfExpire", dateOfExpire)
73
+ putString("documentNumber", documentNumber)
74
+ putInt("age", age)
75
+ putString("mrzText", mrzText)
76
+ }
77
+ }
@@ -0,0 +1,47 @@
1
+ package com.dynamsoft.reactnativelib.rtu
2
+
3
+ import android.app.Activity
4
+ import android.content.Intent
5
+ import com.facebook.react.bridge.ActivityEventListener
6
+ import com.facebook.react.bridge.Promise
7
+ import com.facebook.react.bridge.ReactApplicationContext
8
+ import com.facebook.react.bridge.ReadableMap
9
+ import com.facebook.react.bridge.WritableMap
10
+
11
+ abstract class ScannerModule(private val reactContext: ReactApplicationContext): ActivityEventListener {
12
+
13
+ private var promises: HashMap<Int, Promise> = hashMapOf()
14
+
15
+ abstract fun createIntent(config: ReadableMap): Intent
16
+
17
+ abstract fun getPromiseResolve(intent: Intent): WritableMap
18
+
19
+ override fun onActivityResult(activity: Activity?, requestCode: Int, resultCode: Int, intent: Intent?) {
20
+ if(resultCode != Activity.RESULT_OK || intent == null) {
21
+ promises.remove(requestCode)?.resolve(null)
22
+ return
23
+ } else {
24
+ promises.remove(requestCode)?.apply {
25
+ resolve(getPromiseResolve(intent))
26
+ }
27
+ }
28
+ }
29
+
30
+ override fun onNewIntent(intent: Intent?) {
31
+ //No-op
32
+ }
33
+
34
+ fun startScanner(config: ReadableMap, promise: Promise) {
35
+ reactContext.addActivityEventListener(this)
36
+ promises[promise.hashCode()] = promise
37
+ reactContext.currentActivity?.startActivityForResult(
38
+ createIntent(config),
39
+ promise.hashCode()
40
+ )
41
+ }
42
+
43
+ fun closeScanner(promise: Promise) {
44
+ promise.resolve(null)
45
+ reactContext.removeActivityEventListener(this)
46
+ }
47
+ }
@@ -0,0 +1,22 @@
1
+ package com.dynamsoft.reactnativelib
2
+
3
+ import com.dynamsoft.reactnativelib.rtu.BarcodeScannerModuleImpl
4
+ import com.facebook.react.bridge.Promise
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
7
+ import com.facebook.react.bridge.ReactMethod
8
+ import com.facebook.react.bridge.ReadableMap
9
+
10
+ class BarcodeScannerModule(reactApplicationContext: ReactApplicationContext) : NativeDynamsoftBarcodeScannerModuleSpec(reactApplicationContext) {
11
+ override fun getName() = BarcodeScannerModuleImpl.NAME
12
+
13
+ val impl by lazy { BarcodeScannerModuleImpl(reactApplicationContext) }
14
+
15
+ override fun startBarcodeScanner(config: ReadableMap, promise: Promise) {
16
+ impl.startBarcodeScanner(config, promise)
17
+ }
18
+
19
+ override fun closeBarcodeScanner(promise: Promise) {
20
+ impl.closeBarcodeScanner(promise)
21
+ }
22
+ }
@@ -0,0 +1,22 @@
1
+ package com.dynamsoft.reactnativelib
2
+
3
+ import com.dynamsoft.reactnativelib.rtu.MRZScannerModuleImpl
4
+ import com.facebook.react.bridge.Promise
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
7
+ import com.facebook.react.bridge.ReactMethod
8
+ import com.facebook.react.bridge.ReadableMap
9
+
10
+ class MRZScannerModule(reactApplicationContext: ReactApplicationContext) : NativeDynamsoftMRZScannerModuleSpec(reactApplicationContext) {
11
+ override fun getName() = MRZScannerModuleImpl.NAME
12
+
13
+ val impl by lazy { MRZScannerModuleImpl(reactApplicationContext) }
14
+
15
+ override fun startMRZScanner(config: ReadableMap, promise: Promise) {
16
+ impl.startMRZScanner(config, promise)
17
+ }
18
+
19
+ override fun closeMRZScanner(promise: Promise) {
20
+ impl.closeMRZScanner(promise)
21
+ }
22
+ }
@@ -0,0 +1,24 @@
1
+ package com.dynamsoft.reactnativelib
2
+
3
+ import com.dynamsoft.reactnativelib.rtu.BarcodeScannerModuleImpl
4
+ import com.facebook.react.bridge.Promise
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
7
+ import com.facebook.react.bridge.ReactMethod
8
+ import com.facebook.react.bridge.ReadableMap
9
+
10
+ class BarcodeScannerModule(reactApplicationContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactApplicationContext) {
11
+ override fun getName() = BarcodeScannerModuleImpl.NAME
12
+
13
+ val impl by lazy { BarcodeScannerModuleImpl(reactApplicationContext) }
14
+
15
+ @ReactMethod
16
+ fun startBarcodeScanner(config: ReadableMap, promise: Promise) {
17
+ impl.startBarcodeScanner(config, promise)
18
+ }
19
+
20
+ @ReactMethod
21
+ fun closeBarcodeScanner(promise: Promise) {
22
+ impl.closeBarcodeScanner(promise)
23
+ }
24
+ }
@@ -0,0 +1,24 @@
1
+ package com.dynamsoft.reactnativelib
2
+
3
+ import com.dynamsoft.reactnativelib.rtu.MRZScannerModuleImpl
4
+ import com.facebook.react.bridge.Promise
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
7
+ import com.facebook.react.bridge.ReactMethod
8
+ import com.facebook.react.bridge.ReadableMap
9
+
10
+ class MRZScannerModule(reactApplicationContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactApplicationContext) {
11
+ override fun getName() = MRZScannerModuleImpl.NAME
12
+
13
+ val impl by lazy { MRZScannerModuleImpl(reactApplicationContext) }
14
+
15
+ @ReactMethod
16
+ fun startMRZScanner(config: ReadableMap, promise: Promise) {
17
+ impl.startMRZScanner(config, promise)
18
+ }
19
+
20
+ @ReactMethod
21
+ fun closeMRZScanner(promise: Promise) {
22
+ impl.closeMRZScanner(promise)
23
+ }
24
+ }
@@ -12,9 +12,11 @@ Pod::Spec.new do |s|
12
12
  s.authors = { package["author"]["name"] => package["author"]["email"] }
13
13
  s.platforms = { :ios => "11.0" }
14
14
  s.source = { :http => "https://registry.npmjs.org/#{s.name}/-/#{s.name}-#{s.version}.tgz" }
15
- s.source_files = "ios/**/*.{h,c,cc,cpp,m,mm,swift}"
15
+ s.source_files = "ios/**/*.{h,hpp,c,cc,cpp,m,mm,swift}"
16
16
  s.requires_arc = true
17
17
  s.dependency "React"
18
- s.dependency "DynamsoftCaptureVisionBundle", "= 2.6.1002"
18
+ s.dependency "DynamsoftCaptureVisionBundle", "= 2.6.1004"
19
+ s.dependency "DynamsoftBarcodeReaderBundle", "= 10.4.3002"
20
+ s.dependency "DynamsoftMRZScannerBundle", "= 2.0.1"
19
21
  end
20
22
 
@@ -99,4 +99,6 @@ NS_ASSUME_NONNULL_BEGIN
99
99
 
100
100
  @end
101
101
 
102
+ void runOnMainThread(void (^block)(void));
103
+
102
104
  NS_ASSUME_NONNULL_END
@@ -8,6 +8,15 @@ NSArray<NSNumber *> *CGAffineTransformToArray(CGAffineTransform transform) {
8
8
  return @[@(transform.a), @(transform.b), @(transform.c), @(transform.d), @(transform.tx), @(transform.ty)];
9
9
  }
10
10
 
11
+ void runOnMainThread(void (^block)(void))
12
+ {
13
+ if ([NSThread isMainThread]) {
14
+ block();
15
+ } else {
16
+ dispatch_async(dispatch_get_main_queue(), block);
17
+ }
18
+ }
19
+
11
20
  @implementation DSQuadrilateral (Json)
12
21
 
13
22
  + (nullable DSQuadrilateral *)quadrilateralWithDictionary:(NSDictionary *)dictionary {
@@ -0,0 +1,14 @@
1
+ /*
2
+ * Copyright © Dynamsoft Corporation. All rights reserved.
3
+ */
4
+
5
+ #import "RCTEventEmitter.h"
6
+ #import <React/RCTBridgeModule.h>
7
+
8
+ NS_ASSUME_NONNULL_BEGIN
9
+
10
+ @interface RNDynamsoftBarcodeScanner : RCTEventEmitter <RCTBridgeModule>
11
+
12
+ @end
13
+
14
+ NS_ASSUME_NONNULL_END