scandit-react-native-datacapture-core 8.1.1 → 8.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/THIRD_PARTY.txt CHANGED
@@ -284,7 +284,6 @@ includes components licensed under the following licenses:
284
284
 
285
285
  ================================================================================
286
286
 
287
-
288
287
  Copyright (c) 2017 Ollix
289
288
 
290
289
  Permission is hereby granted, free of charge, to any person
@@ -39,6 +39,13 @@ buildscript {
39
39
  }
40
40
  }
41
41
 
42
+ def isNewArchitectureEnabled() {
43
+ // To opt-in for the New Architecture, you can either:
44
+ // - Set `newArchEnabled` to true inside the `gradle.properties` file
45
+ // - Invoke gradle with `-newArchEnabled=true`
46
+ // - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
47
+ return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
48
+ }
42
49
  android {
43
50
  if (supportsNamespace()) {
44
51
  sourceSets {
@@ -50,6 +57,19 @@ android {
50
57
  }
51
58
 
52
59
  compileSdkVersion safeExtGet("compileSdkVersion", 33)
60
+
61
+ sourceSets {
62
+ main {
63
+ if (supportsNamespace()) {
64
+ manifest.srcFile "src/main/AndroidManifestNew.xml" // no package on it
65
+ }
66
+ if (this.isNewArchitectureEnabled()) {
67
+ kotlin.srcDirs += ['src/main/newArch/kotlin']
68
+ } else {
69
+ kotlin.srcDirs += ['src/main/oldArch/kotlin']
70
+ }
71
+ }
72
+ }
53
73
 
54
74
  defaultConfig {
55
75
  minSdkVersion safeExtGet("minSdkVersion", 24)
@@ -68,7 +88,7 @@ if (file( "${rootProject.projectDir}/build-test.gradle").exists()) {
68
88
  }
69
89
 
70
90
  dependencies {
71
- def sdk_version = "8.1.1"
91
+ def sdk_version = "8.2.0"
72
92
 
73
93
  println("Version of the native sdk used in this build: ${safeExtGet('global_sdk_version', sdk_version)}")
74
94
  if (findProject(':scandit-datacapture-frameworks-core') != null) {
@@ -11,6 +11,7 @@ import com.facebook.react.bridge.ReactApplicationContext
11
11
  import com.facebook.react.bridge.ReactContextBaseJavaModule
12
12
  import com.facebook.react.bridge.ReactMethod
13
13
  import com.facebook.react.bridge.ReadableMap
14
+ import com.facebook.react.module.annotations.ReactModule
14
15
  import com.facebook.react.uimanager.ViewGroupManager
15
16
  import com.scandit.datacapture.core.capture.DataCaptureVersion
16
17
  import com.scandit.datacapture.frameworks.core.CoreModule
@@ -19,16 +20,18 @@ import com.scandit.datacapture.frameworks.core.errors.ModuleNotStartedError
19
20
  import com.scandit.datacapture.frameworks.core.errors.ParameterNullError
20
21
  import com.scandit.datacapture.frameworks.core.locator.ServiceLocator
21
22
  import com.scandit.datacapture.reactnative.core.ui.DataCaptureViewManager
23
+ import com.scandit.datacapture.reactnative.core.utils.ReactNativeMethodCall
22
24
  import com.scandit.datacapture.reactnative.core.utils.ReactNativeResult
23
- import com.scandit.datacapture.reactnative.core.utils.viewId
24
25
 
25
- class ScanditDataCaptureCoreModule(
26
+ @ReactModule(name = ScanditDataCaptureCoreModule.NAME)
27
+ open class ScanditDataCaptureCoreModule(
26
28
  reactContext: ReactApplicationContext,
27
29
  private val serviceLocator: ServiceLocator<FrameworkModule>,
28
30
  private val viewManagers: Map<String, ViewGroupManager<*>>,
29
31
  ) : ReactContextBaseJavaModule(reactContext) {
30
32
 
31
33
  companion object {
34
+ const val NAME = "ScanditDataCaptureCore"
32
35
  private const val VERSION_KEY = "Version"
33
36
  private const val DEFAULTS_KEY = "Defaults"
34
37
 
@@ -43,159 +46,21 @@ class ScanditDataCaptureCoreModule(
43
46
  super.invalidate()
44
47
  }
45
48
 
46
- override fun getName(): String = "ScanditDataCaptureCore"
49
+ override fun getName(): String = NAME
47
50
 
48
- override fun getConstants(): MutableMap<String, Any> = mutableMapOf(
49
- VERSION_KEY to DataCaptureVersion.VERSION_STRING,
50
- DEFAULTS_KEY to coreModule.getDefaults()
51
- )
52
-
53
- @ReactMethod
54
- fun subscribeContextListener() {
55
- coreModule.registerDataCaptureContextListener()
56
- }
57
-
58
- @ReactMethod
59
- fun unsubscribeContextListener() {
60
- coreModule.unregisterDataCaptureContextListener()
61
- }
62
-
63
- @ReactMethod
64
- fun registerListenerForCameraEvents(promise: Promise) {
65
- coreModule.registerFrameSourceListener()
66
- promise.resolve(null)
67
- }
68
-
69
- @ReactMethod
70
- fun unregisterListenerForCameraEvents(promise: Promise) {
71
- coreModule.unregisterFrameSourceListener()
72
- promise.resolve(null)
73
- }
74
-
75
- @ReactMethod
76
- fun registerListenerForViewEvents(readableMap: ReadableMap) {
77
- coreModule.registerDataCaptureViewListener(readableMap.viewId)
78
- }
79
-
80
- @ReactMethod
81
- fun unregisterListenerForViewEvents(readableMap: ReadableMap) {
82
- coreModule.unregisterDataCaptureViewListener(readableMap.viewId)
83
- }
84
-
85
- @ReactMethod
86
- fun contextFromJSON(readableMap: ReadableMap, promise: Promise) {
87
- val contextJson = readableMap.getString("contextJson") ?: return promise.reject(
88
- ParameterNullError("contextJson")
89
- )
90
- coreModule.createContextFromJson(contextJson, ReactNativeResult(promise))
91
- }
92
-
93
- @ReactMethod
94
- fun updateContextFromJSON(readableMap: ReadableMap, promise: Promise) {
95
- val contextJson = readableMap.getString("contextJson") ?: return promise.reject(
96
- ParameterNullError("contextJson")
97
- )
98
- coreModule.updateContextFromJson(contextJson, ReactNativeResult(promise))
99
- }
100
-
101
- @ReactMethod
102
- fun getFrame(readableMap: ReadableMap, promise: Promise) {
103
- val frameId = readableMap.getString("frameId") ?: return promise.reject(
104
- ParameterNullError("frameId")
105
- )
106
- coreModule.getLastFrameAsJson(frameId, ReactNativeResult(promise))
107
- }
108
-
109
- @ReactMethod
110
- fun disposeContext() {
111
- coreModule.disposeContext()
112
- }
113
-
114
- @ReactMethod
115
- fun emitFeedback(readableMap: ReadableMap, promise: Promise) {
116
- val feedbackJson = readableMap.getString("feedbackJson") ?: return promise.reject(
117
- ParameterNullError("feedbackJson")
118
- )
119
- coreModule.emitFeedback(feedbackJson, ReactNativeResult(promise))
120
- }
121
-
122
- @ReactMethod
123
- fun viewPointForFramePoint(readableMap: ReadableMap, promise: Promise) {
124
- val pointJson = readableMap.getString("pointJson") ?: return promise.reject(
125
- ParameterNullError("pointJson")
126
- )
127
-
128
- coreModule.viewPointForFramePoint(
129
- readableMap.viewId,
130
- pointJson,
131
- ReactNativeResult(promise)
51
+ override fun getConstants(): MutableMap<String, Any> {
52
+ return mutableMapOf(
53
+ VERSION_KEY to DataCaptureVersion.VERSION_STRING,
54
+ DEFAULTS_KEY to coreModule.getDefaults()
132
55
  )
133
56
  }
134
57
 
135
- @ReactMethod
136
- fun viewQuadrilateralForFrameQuadrilateral(readableMap: ReadableMap, promise: Promise) {
137
- val quadrilateralJson = readableMap.getString("quadrilateralJson") ?: return promise.reject(
138
- ParameterNullError("quadrilateralJson")
139
- )
140
-
141
- coreModule.viewQuadrilateralForFrameQuadrilateral(
142
- readableMap.viewId,
143
- quadrilateralJson,
144
- ReactNativeResult(promise)
145
- )
146
- }
147
-
148
- @ReactMethod
149
- fun getCurrentCameraState(readableMap: ReadableMap, promise: Promise) {
150
- val cameraPosition = readableMap.getString("position") ?: return promise.reject(
151
- ParameterNullError("position")
152
- )
153
- coreModule.getCameraState(cameraPosition, ReactNativeResult(promise))
154
- }
155
-
156
- @ReactMethod
157
- fun isTorchAvailable(readableMap: ReadableMap, promise: Promise) {
158
- val cameraPosition = readableMap.getString("position") ?: return promise.reject(
159
- ParameterNullError("position")
160
- )
161
- coreModule.isTorchAvailable(cameraPosition, ReactNativeResult(promise))
162
- }
163
-
164
- @ReactMethod
165
- fun switchCameraToDesiredState(readableMap: ReadableMap, promise: Promise) {
166
- val desiredStateJson = readableMap.getString("desiredStateJson") ?: return promise.reject(
167
- ParameterNullError("desiredStateJson")
168
- )
169
- coreModule.switchCameraToDesiredState(desiredStateJson, ReactNativeResult(promise))
170
- }
171
-
172
- @ReactMethod
173
- fun addModeToContext(readableMap: ReadableMap, promise: Promise) {
174
- val modeJson = readableMap.getString("modeJson") ?: return promise.reject(
175
- ParameterNullError("modeJson")
176
- )
177
- coreModule.addModeToContext(modeJson, ReactNativeResult(promise))
178
- }
179
-
180
- @ReactMethod
181
- fun removeModeFromContext(readableMap: ReadableMap, promise: Promise) {
182
- val modeJson = readableMap.getString("modeJson") ?: return promise.reject(
183
- ParameterNullError("modeJson")
184
- )
185
- coreModule.removeModeFromContext(modeJson, ReactNativeResult(promise))
186
- }
187
-
188
- @ReactMethod
189
- fun removeAllModes(promise: Promise) {
190
- coreModule.removeAllModes(ReactNativeResult(promise))
191
- }
192
-
193
58
  @ReactMethod
194
59
  fun createDataCaptureView(readableMap: ReadableMap, promise: Promise) {
195
60
  val viewJson = readableMap.getString("viewJson") ?: return promise.reject(
196
61
  ParameterNullError("viewJson")
197
62
  )
198
- val viewManager = viewManagers[DataCaptureViewManager::class.java.name] as?
63
+ val viewManager = viewManagers[DataCaptureViewManager::class.java.simpleName] as?
199
64
  DataCaptureViewManager
200
65
  if (viewManager == null) {
201
66
  promise.reject(VIEW_MANAGER_NULL_ERROR)
@@ -205,14 +70,6 @@ class ScanditDataCaptureCoreModule(
205
70
  viewManager.createDataCaptureView(viewJson, promise)
206
71
  }
207
72
 
208
- @ReactMethod
209
- fun updateDataCaptureView(readableMap: ReadableMap, promise: Promise) {
210
- val viewJson = readableMap.getString("viewJson") ?: return promise.reject(
211
- ParameterNullError("viewJson")
212
- )
213
- coreModule.updateDataCaptureView(viewJson, ReactNativeResult(promise))
214
- }
215
-
216
73
  @ReactMethod
217
74
  fun removeDataCaptureView(
218
75
  @Suppress("unused") readableMap: ReadableMap,
@@ -222,11 +79,6 @@ class ScanditDataCaptureCoreModule(
222
79
  promise.resolve(null)
223
80
  }
224
81
 
225
- @ReactMethod
226
- fun getOpenSourceSoftwareLicenseInfo(promise: Promise) {
227
- coreModule.getOpenSourceSoftwareLicenseInfo(ReactNativeResult(promise))
228
- }
229
-
230
82
  @ReactMethod
231
83
  fun addListener(@Suppress("UNUSED_PARAMETER") eventName: String?) {
232
84
  // Keep: Required for RN built in Event Emitter Calls.
@@ -237,9 +89,29 @@ class ScanditDataCaptureCoreModule(
237
89
  // Keep: Required for RN built in Event Emitter Calls.
238
90
  }
239
91
 
92
+ /**
93
+ * Single entry point for all Core operations.
94
+ * Routes method calls to the appropriate command via the shared command factory.
95
+ */
96
+ @ReactMethod
97
+ fun executeCore(data: ReadableMap, promise: Promise) {
98
+ val handled = coreModule.execute(
99
+ ReactNativeMethodCall(data),
100
+ ReactNativeResult(promise),
101
+ coreModule
102
+ )
103
+ if (!handled) {
104
+ val methodName = data.getString("methodName") ?: "unknown"
105
+ promise.reject(
106
+ "METHOD_NOT_FOUND",
107
+ "Unknown Core method: $methodName"
108
+ )
109
+ }
110
+ }
111
+
240
112
  private val coreModule: CoreModule
241
113
  get() {
242
- return serviceLocator.resolve(CoreModule::class.java.name) as? CoreModule?
114
+ return serviceLocator.resolve(CoreModule::class.java.simpleName) as? CoreModule?
243
115
  ?: throw ModuleNotStartedError(ScanditDataCaptureCoreModule::class.java.simpleName)
244
116
  }
245
117
  }
@@ -5,7 +5,6 @@
5
5
  */
6
6
  package com.scandit.datacapture.reactnative.core
7
7
 
8
- import com.facebook.react.ReactPackage
9
8
  import com.facebook.react.bridge.LifecycleEventListener
10
9
  import com.facebook.react.bridge.NativeModule
11
10
  import com.facebook.react.bridge.ReactApplicationContext
@@ -21,7 +20,7 @@ import com.scandit.datacapture.reactnative.core.utils.ReactNativeEventEmitter
21
20
  import java.util.concurrent.ConcurrentHashMap
22
21
  import java.util.concurrent.locks.ReentrantLock
23
22
 
24
- class ScanditDataCaptureCorePackage : ReactPackage {
23
+ class ScanditDataCaptureCorePackage : ScanditReactPackageBase() {
25
24
  private val serviceLocator = DefaultServiceLocator.getInstance()
26
25
 
27
26
  private val lifecycleDispatcher: ActivityLifecycleDispatcher =
@@ -50,12 +49,10 @@ class ScanditDataCaptureCorePackage : ReactPackage {
50
49
  reactContext.addLifecycleEventListener(lifecycleListener)
51
50
 
52
51
  setupSharedModule(reactContext)
52
+
53
+ // Use legacy module for both architectures (Interop Layer)
53
54
  return mutableListOf(
54
- ScanditDataCaptureCoreModule(
55
- reactContext,
56
- serviceLocator,
57
- viewManagers,
58
- )
55
+ ScanditDataCaptureCoreModule(reactContext, serviceLocator, viewManagers)
59
56
  )
60
57
  }
61
58
 
@@ -64,15 +61,19 @@ class ScanditDataCaptureCorePackage : ReactPackage {
64
61
  ): MutableList<ViewManager<*, *>> {
65
62
  // Clear existing instances of previously cached viewMangers
66
63
  viewManagers.clear()
64
+ clearCache()
67
65
 
68
66
  val dcViewManager = DataCaptureViewManager(serviceLocator)
69
67
  // Here we register the ViewManagers and allow the different module to access them by
70
68
  // using the name.
71
- viewManagers[DataCaptureViewManager::class.java.name] = dcViewManager
69
+ viewManagers[DataCaptureViewManager::class.java.simpleName] = dcViewManager
72
70
 
73
71
  return mutableListOf(dcViewManager)
74
72
  }
75
73
 
74
+ override fun getModuleClasses(): List<Class<out NativeModule>> =
75
+ listOf(ScanditDataCaptureCoreModule::class.java)
76
+
76
77
  private fun setupSharedModule(reactContext: ReactApplicationContext) {
77
78
  lock.lock()
78
79
  try {
@@ -99,7 +99,7 @@ class DataCaptureViewManager(
99
99
 
100
100
  private val coreModule: CoreModule
101
101
  get() {
102
- return serviceLocator.resolve(CoreModule::class.java.name) as? CoreModule?
102
+ return serviceLocator.resolve(CoreModule::class.java.simpleName) as? CoreModule?
103
103
  ?: throw ModuleNotStartedError(DataCaptureViewManager::class.java.simpleName)
104
104
  }
105
105
 
@@ -7,21 +7,10 @@
7
7
  package com.scandit.datacapture.reactnative.core.utils
8
8
 
9
9
  import com.facebook.react.bridge.*
10
- import com.scandit.datacapture.core.common.geometry.MeasureUnit
11
- import com.scandit.datacapture.core.common.geometry.PointWithUnit
12
- import com.scandit.datacapture.frameworks.core.utils.DefaultFrameworksLog
13
- import com.scandit.datacapture.reactnative.core.data.SerializableData
14
- import java.util.*
15
-
16
- val POINT_WITH_UNIT_ZERO: PointWithUnit = PointWithUnit(0f, 0f, MeasureUnit.PIXEL)
17
10
 
18
11
  inline fun writableMap(builder: WritableMap.() -> Unit): WritableMap =
19
12
  Arguments.createMap().apply(builder)
20
13
 
21
- fun WritableMap.putData(key: String, data: SerializableData) {
22
- putMap(key, data.toWritableMap())
23
- }
24
-
25
14
  inline fun <reified T : JavaScriptModule> ReactApplicationContext.getJSModule(): T =
26
15
  getJSModule(T::class.java)
27
16
 
@@ -30,32 +19,3 @@ val ReadableMap.viewId: Int
30
19
 
31
20
  val ReadableMap.modeId: Int
32
21
  get() = this.getInt("modeId")
33
-
34
- fun ReadableMap.getSafeLong(key: String): Long? {
35
- if (!hasKey(key) || isNull(key)) return null
36
-
37
- return try {
38
- when (getType(key)) {
39
- ReadableType.Number -> {
40
- val doubleValue = getDouble(key)
41
- val longValue = doubleValue.toLong()
42
- require(doubleValue == longValue.toDouble())
43
- longValue
44
- }
45
-
46
- ReadableType.String ->
47
- getString(key)?.toLongOrNull()
48
- ?: throw IllegalArgumentException(
49
- "Value for '$key' is not a valid long string."
50
- )
51
-
52
- else -> throw IllegalArgumentException(
53
- "Unsupported type for '$key'. Expected number or string."
54
- )
55
- }
56
- } catch (e: Exception) {
57
- DefaultFrameworksLog.getInstance()
58
- .error("Failed to parse long for key '$key': ${e.message}", e)
59
- return null
60
- }
61
- }
@@ -0,0 +1,84 @@
1
+ /*
2
+ * This file is part of the Scandit Data Capture SDK
3
+ *
4
+ * Copyright (C) 2025- Scandit AG. All rights reserved.
5
+ */
6
+
7
+ package com.scandit.datacapture.reactnative.core
8
+
9
+ import com.facebook.react.TurboReactPackage
10
+ import com.facebook.react.bridge.NativeModule
11
+ import com.facebook.react.bridge.ReactApplicationContext
12
+ import com.facebook.react.module.annotations.ReactModule
13
+ import com.facebook.react.module.model.ReactModuleInfo
14
+ import com.facebook.react.module.model.ReactModuleInfoProvider
15
+ import java.util.concurrent.ConcurrentHashMap
16
+
17
+ /**
18
+ * Base class for React Native packages in the new architecture.
19
+ *
20
+ * This uses the Interop Layer approach:
21
+ * - Legacy modules (ReactContextBaseJavaModule) work in new architecture
22
+ * - Modules are registered with @ReactModule annotation
23
+ * - isTurboModule = false uses React Native's Interop bridge adapter
24
+ * - No JSI/Codegen required
25
+ * - Compatible with both architectures and bridgeless mode
26
+ */
27
+ abstract class ScanditReactPackageBase : TurboReactPackage() {
28
+ @Suppress("unused")
29
+ protected val isNewArchitectureEnabled: Boolean = true
30
+
31
+ // Cache modules per context to avoid recreating them
32
+ private val moduleCache = ConcurrentHashMap<String, ConcurrentHashMap<String, NativeModule>>()
33
+
34
+ override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
35
+ // Get or create context-specific cache
36
+ val contextId = System.identityHashCode(reactContext).toString()
37
+
38
+ val contextCache = moduleCache.getOrPut(contextId) {
39
+ // Pre-populate cache with modules from createNativeModules()
40
+ val preCreatedModules = createNativeModules(reactContext)
41
+ val cache = ConcurrentHashMap<String, NativeModule>()
42
+ preCreatedModules.forEach { module ->
43
+ cache[module.name] = module
44
+ }
45
+ cache
46
+ }
47
+
48
+ return contextCache[name]
49
+ }
50
+
51
+ override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
52
+ return ReactModuleInfoProvider {
53
+ val moduleInfoMap = mutableMapOf<String, ReactModuleInfo>()
54
+
55
+ // Extract module info from @ReactModule annotations
56
+ getModuleClasses().forEach { moduleClass ->
57
+ val annotation = moduleClass.getAnnotation(ReactModule::class.java)
58
+ if (annotation != null) {
59
+ moduleInfoMap[annotation.name] = ReactModuleInfo(
60
+ annotation.name,
61
+ className = moduleClass.name,
62
+ canOverrideExistingModule = true,
63
+ needsEagerInit = true,
64
+ hasConstants = true,
65
+ isCxxModule = false,
66
+ isTurboModule = false // false for Interop layer
67
+ )
68
+ }
69
+ }
70
+
71
+ moduleInfoMap
72
+ }
73
+ }
74
+
75
+ /**
76
+ * Subclasses must override this to provide the list of module classes
77
+ * they want to register.
78
+ */
79
+ protected abstract fun getModuleClasses(): List<Class<out NativeModule>>
80
+
81
+ fun clearCache() {
82
+ moduleCache.clear()
83
+ }
84
+ }
@@ -0,0 +1,17 @@
1
+ /*
2
+ * This file is part of the Scandit Data Capture SDK
3
+ *
4
+ * Copyright (C) 2025- Scandit AG. All rights reserved.
5
+ */
6
+
7
+ package com.scandit.datacapture.reactnative.core
8
+
9
+ import com.facebook.react.ReactPackage
10
+ import com.facebook.react.bridge.NativeModule
11
+
12
+ abstract class ScanditReactPackageBase : ReactPackage {
13
+ protected val isNewArchitectureEnabled: Boolean = false
14
+ protected abstract fun getModuleClasses(): List<Class<out NativeModule>>
15
+
16
+ fun clearCache()
17
+ }