scandit-react-native-datacapture-core 8.2.1 → 8.3.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/android/build.gradle +20 -9
- package/android/generated/java/com/facebook/fbreact/specs/NativeScanditDataCaptureCoreSpec.java +83 -0
- package/android/generated/java/com/facebook/react/viewmanagers/RNTDataCaptureViewManagerDelegate.java +26 -0
- package/android/generated/java/com/facebook/react/viewmanagers/RNTDataCaptureViewManagerInterface.java +16 -0
- package/android/generated/jni/CMakeLists.txt +29 -0
- package/android/generated/jni/ScanditReactNativeDatacaptureCoreSpec-generated.cpp +52 -0
- package/android/generated/jni/ScanditReactNativeDatacaptureCoreSpec.h +31 -0
- package/android/generated/jni/react/renderer/components/ScanditReactNativeDatacaptureCoreSpec/ComponentDescriptors.cpp +22 -0
- package/android/generated/jni/react/renderer/components/ScanditReactNativeDatacaptureCoreSpec/ComponentDescriptors.h +24 -0
- package/android/generated/jni/react/renderer/components/ScanditReactNativeDatacaptureCoreSpec/EventEmitters.cpp +16 -0
- package/android/generated/jni/react/renderer/components/ScanditReactNativeDatacaptureCoreSpec/EventEmitters.h +23 -0
- package/android/generated/jni/react/renderer/components/ScanditReactNativeDatacaptureCoreSpec/Props.cpp +25 -0
- package/android/generated/jni/react/renderer/components/ScanditReactNativeDatacaptureCoreSpec/Props.h +27 -0
- package/android/generated/jni/react/renderer/components/ScanditReactNativeDatacaptureCoreSpec/ScanditReactNativeDatacaptureCoreSpecJSI-generated.cpp +47 -0
- package/android/generated/jni/react/renderer/components/ScanditReactNativeDatacaptureCoreSpec/ScanditReactNativeDatacaptureCoreSpecJSI.h +169 -0
- package/android/generated/jni/react/renderer/components/ScanditReactNativeDatacaptureCoreSpec/ShadowNodes.cpp +17 -0
- package/android/generated/jni/react/renderer/components/ScanditReactNativeDatacaptureCoreSpec/ShadowNodes.h +32 -0
- package/android/generated/jni/react/renderer/components/ScanditReactNativeDatacaptureCoreSpec/States.cpp +16 -0
- package/android/generated/jni/react/renderer/components/ScanditReactNativeDatacaptureCoreSpec/States.h +29 -0
- package/android/src/main/AndroidManifest.xml +3 -1
- package/android/src/main/AndroidManifestNew.xml +3 -1
- package/android/src/main/kotlin/com/scandit/datacapture/reactnative/core/{ScanditDataCaptureCoreModule.kt → ScanditDataCaptureCoreModuleBase.kt} +15 -40
- package/android/src/main/kotlin/com/scandit/datacapture/reactnative/core/ScanditDataCaptureCorePackage.kt +1 -23
- package/android/src/main/kotlin/com/scandit/datacapture/reactnative/core/ui/{DataCaptureViewManager.kt → DataCaptureViewManagerBase.kt} +9 -4
- package/android/src/main/newArch/kotlin/com/scandit/datacapture/reactnative/core/ScanditDataCaptureCoreModule.kt +72 -0
- package/android/src/main/newArch/kotlin/com/scandit/datacapture/reactnative/core/ScanditReactPackageBase.kt +44 -11
- package/android/src/main/newArch/kotlin/com/scandit/datacapture/reactnative/core/ui/DataCaptureViewManager.kt +31 -0
- package/android/src/main/newArch/kotlin/com/scandit/datacapture/reactnative/core/utils/ReactNativeEventEmitter.kt +39 -0
- package/android/src/main/oldArch/kotlin/com/scandit/datacapture/reactnative/core/ScanditDataCaptureCoreModule.kt +86 -0
- package/android/src/main/oldArch/kotlin/com/scandit/datacapture/reactnative/core/ScanditReactPackageBase.kt +2 -2
- package/android/src/main/oldArch/kotlin/com/scandit/datacapture/reactnative/core/ui/DataCaptureViewManager.kt +18 -0
- package/android/src/main/{kotlin → oldArch/kotlin}/com/scandit/datacapture/reactnative/core/utils/ReactNativeEventEmitter.kt +4 -1
- package/dist/core.js +871 -69
- package/dist/core.js.map +1 -1
- package/dist/dts/DataCaptureView.d.ts +3 -0
- package/dist/dts/index.d.ts +79 -13
- package/dist/dts/native/RNNativeCaller.d.ts +8 -1
- package/dist/index.js +44 -7
- package/dist/index.js.flow +79 -99
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/ios/Sources/NewArch/RCTDataCaptureView.mm +110 -0
- package/ios/Sources/NewArch/ScanditDataCaptureCore.mm +102 -0
- package/ios/Sources/OldArch/RCTFabricDataCaptureViewContainers.mm +17 -0
- package/ios/Sources/OldArch/ScanditDataCaptureCore.mm +92 -0
- package/ios/Sources/RNTSDCDataCaptureViewManager.swift +41 -0
- package/ios/Sources/SDCLogger.h +11 -0
- package/ios/Sources/SDCLogger.m +16 -0
- package/ios/Sources/SDCTurboModuleEventBridge.h +42 -0
- package/ios/Sources/SDCTurboModuleEventBridge.m +20 -0
- package/ios/Sources/ScanditDataCaptureCore-Bridging-Header.h +3 -0
- package/ios/Sources/ScanditDataCaptureCore.h +35 -1
- package/ios/Sources/ScanditDataCaptureCore.swift +134 -60
- package/ios/Sources/Shared/DataCaptureViewWrapper.swift +129 -0
- package/ios/Sources/{Protocols → Shared}/ScanditReactNativeFactoryContainer.swift +7 -3
- package/ios/Sources/Utils/CallbackLock.swift +1 -1
- package/ios/Sources/Utils/ReactNativeEmitter.swift +43 -10
- package/ios/generated/ScanditReactNativeDatacaptureCoreSpec/ComponentDescriptors.cpp +22 -0
- package/ios/generated/ScanditReactNativeDatacaptureCoreSpec/ComponentDescriptors.h +24 -0
- package/ios/generated/ScanditReactNativeDatacaptureCoreSpec/EventEmitters.cpp +16 -0
- package/ios/generated/ScanditReactNativeDatacaptureCoreSpec/EventEmitters.h +23 -0
- package/ios/generated/ScanditReactNativeDatacaptureCoreSpec/Props.cpp +25 -0
- package/ios/generated/ScanditReactNativeDatacaptureCoreSpec/Props.h +27 -0
- package/ios/generated/ScanditReactNativeDatacaptureCoreSpec/RCTComponentViewHelpers.h +20 -0
- package/ios/generated/ScanditReactNativeDatacaptureCoreSpec/ScanditReactNativeDatacaptureCoreSpec-generated.mm +67 -0
- package/ios/generated/ScanditReactNativeDatacaptureCoreSpec/ScanditReactNativeDatacaptureCoreSpec.h +109 -0
- package/ios/generated/ScanditReactNativeDatacaptureCoreSpec/ShadowNodes.cpp +17 -0
- package/ios/generated/ScanditReactNativeDatacaptureCoreSpec/ShadowNodes.h +32 -0
- package/ios/generated/ScanditReactNativeDatacaptureCoreSpec/States.cpp +16 -0
- package/ios/generated/ScanditReactNativeDatacaptureCoreSpec/States.h +29 -0
- package/ios/generated/ScanditReactNativeDatacaptureCoreSpecJSI-generated.cpp +47 -0
- package/ios/generated/ScanditReactNativeDatacaptureCoreSpecJSI.h +169 -0
- package/package.json +26 -7
- package/react-native.config.js +12 -0
- package/scandit-react-native-datacapture-core.podspec +49 -17
- package/specs/NativeScanditDataCaptureCore.ts +36 -0
- package/specs/RNTDataCaptureViewNativeComponent.ts +14 -0
- package/ios/Sources/ScanditDataCaptureCore.m +0 -30
- package/ios/Sources/ScanditDataCaptureViewManager.swift +0 -68
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
+
*
|
|
5
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
6
|
+
* once the code is regenerated.
|
|
7
|
+
*
|
|
8
|
+
* @generated by codegen project: GenerateShadowNodeCpp.js
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#include "ShadowNodes.h"
|
|
12
|
+
|
|
13
|
+
namespace facebook::react {
|
|
14
|
+
|
|
15
|
+
extern const char RNTDataCaptureViewComponentName[] = "RNTDataCaptureView";
|
|
16
|
+
|
|
17
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
+
*
|
|
5
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
6
|
+
* once the code is regenerated.
|
|
7
|
+
*
|
|
8
|
+
* @generated by codegen project: GenerateShadowNodeH.js
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#pragma once
|
|
12
|
+
|
|
13
|
+
#include "EventEmitters.h"
|
|
14
|
+
#include "Props.h"
|
|
15
|
+
#include "States.h"
|
|
16
|
+
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
|
|
17
|
+
#include <jsi/jsi.h>
|
|
18
|
+
|
|
19
|
+
namespace facebook::react {
|
|
20
|
+
|
|
21
|
+
JSI_EXPORT extern const char RNTDataCaptureViewComponentName[];
|
|
22
|
+
|
|
23
|
+
/*
|
|
24
|
+
* `ShadowNode` for <RNTDataCaptureView> component.
|
|
25
|
+
*/
|
|
26
|
+
using RNTDataCaptureViewShadowNode = ConcreteViewShadowNode<
|
|
27
|
+
RNTDataCaptureViewComponentName,
|
|
28
|
+
RNTDataCaptureViewProps,
|
|
29
|
+
RNTDataCaptureViewEventEmitter,
|
|
30
|
+
RNTDataCaptureViewState>;
|
|
31
|
+
|
|
32
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
+
*
|
|
5
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
6
|
+
* once the code is regenerated.
|
|
7
|
+
*
|
|
8
|
+
* @generated by codegen project: GenerateStateCpp.js
|
|
9
|
+
*/
|
|
10
|
+
#include "States.h"
|
|
11
|
+
|
|
12
|
+
namespace facebook::react {
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
3
|
+
*
|
|
4
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
5
|
+
* once the code is regenerated.
|
|
6
|
+
*
|
|
7
|
+
* @generated by codegen project: GenerateStateH.js
|
|
8
|
+
*/
|
|
9
|
+
#pragma once
|
|
10
|
+
|
|
11
|
+
#ifdef ANDROID
|
|
12
|
+
#include <folly/dynamic.h>
|
|
13
|
+
#endif
|
|
14
|
+
|
|
15
|
+
namespace facebook::react {
|
|
16
|
+
|
|
17
|
+
class RNTDataCaptureViewState {
|
|
18
|
+
public:
|
|
19
|
+
RNTDataCaptureViewState() = default;
|
|
20
|
+
|
|
21
|
+
#ifdef ANDROID
|
|
22
|
+
RNTDataCaptureViewState(RNTDataCaptureViewState const &previousState, folly::dynamic data){};
|
|
23
|
+
folly::dynamic getDynamic() const {
|
|
24
|
+
return {};
|
|
25
|
+
};
|
|
26
|
+
#endif
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
} // namespace facebook::react
|
|
@@ -7,13 +7,8 @@
|
|
|
7
7
|
package com.scandit.datacapture.reactnative.core
|
|
8
8
|
|
|
9
9
|
import com.facebook.react.bridge.Promise
|
|
10
|
-
import com.facebook.react.bridge.ReactApplicationContext
|
|
11
|
-
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
12
|
-
import com.facebook.react.bridge.ReactMethod
|
|
13
10
|
import com.facebook.react.bridge.ReadableMap
|
|
14
|
-
import com.facebook.react.module.annotations.ReactModule
|
|
15
11
|
import com.facebook.react.uimanager.ViewGroupManager
|
|
16
|
-
import com.scandit.datacapture.core.capture.DataCaptureVersion
|
|
17
12
|
import com.scandit.datacapture.frameworks.core.CoreModule
|
|
18
13
|
import com.scandit.datacapture.frameworks.core.FrameworkModule
|
|
19
14
|
import com.scandit.datacapture.frameworks.core.errors.ModuleNotStartedError
|
|
@@ -23,16 +18,16 @@ import com.scandit.datacapture.reactnative.core.ui.DataCaptureViewManager
|
|
|
23
18
|
import com.scandit.datacapture.reactnative.core.utils.ReactNativeMethodCall
|
|
24
19
|
import com.scandit.datacapture.reactnative.core.utils.ReactNativeResult
|
|
25
20
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Base implementation for the Scandit Data Capture Core module.
|
|
23
|
+
* Contains all shared business logic used by both old and new architecture modules.
|
|
24
|
+
*/
|
|
25
|
+
class ScanditDataCaptureCoreModuleBase(
|
|
29
26
|
private val serviceLocator: ServiceLocator<FrameworkModule>,
|
|
30
27
|
private val viewManagers: Map<String, ViewGroupManager<*>>,
|
|
31
|
-
)
|
|
32
|
-
|
|
28
|
+
) {
|
|
33
29
|
companion object {
|
|
34
30
|
const val NAME = "ScanditDataCaptureCore"
|
|
35
|
-
private const val VERSION_KEY = "Version"
|
|
36
31
|
private const val DEFAULTS_KEY = "Defaults"
|
|
37
32
|
|
|
38
33
|
private val VIEW_MANAGER_NULL_ERROR = Error(
|
|
@@ -41,23 +36,18 @@ open class ScanditDataCaptureCoreModule(
|
|
|
41
36
|
)
|
|
42
37
|
}
|
|
43
38
|
|
|
44
|
-
|
|
45
|
-
coreModule.onDestroy()
|
|
46
|
-
super.invalidate()
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
override fun getName(): String = NAME
|
|
50
|
-
|
|
51
|
-
override fun getConstants(): MutableMap<String, Any> {
|
|
39
|
+
fun getDefaults(): MutableMap<String, Any> {
|
|
52
40
|
return mutableMapOf(
|
|
53
|
-
VERSION_KEY to DataCaptureVersion.VERSION_STRING,
|
|
54
41
|
DEFAULTS_KEY to coreModule.getDefaults()
|
|
55
42
|
)
|
|
56
43
|
}
|
|
57
44
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
45
|
+
fun onInvalidate() {
|
|
46
|
+
serviceLocator.remove(CoreModule::class.java.simpleName)?.onDestroy()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
fun createDataCaptureView(data: ReadableMap, promise: Promise) {
|
|
50
|
+
val viewJson = data.getString("viewJson") ?: return promise.reject(
|
|
61
51
|
ParameterNullError("viewJson")
|
|
62
52
|
)
|
|
63
53
|
val viewManager = viewManagers[DataCaptureViewManager::class.java.simpleName] as?
|
|
@@ -70,30 +60,15 @@ open class ScanditDataCaptureCoreModule(
|
|
|
70
60
|
viewManager.createDataCaptureView(viewJson, promise)
|
|
71
61
|
}
|
|
72
62
|
|
|
73
|
-
|
|
74
|
-
fun removeDataCaptureView(
|
|
75
|
-
@Suppress("unused") readableMap: ReadableMap,
|
|
76
|
-
promise: Promise
|
|
77
|
-
) {
|
|
63
|
+
fun removeDataCaptureView(promise: Promise) {
|
|
78
64
|
// Handled through the ViewManager
|
|
79
65
|
promise.resolve(null)
|
|
80
66
|
}
|
|
81
67
|
|
|
82
|
-
@ReactMethod
|
|
83
|
-
fun addListener(@Suppress("UNUSED_PARAMETER") eventName: String?) {
|
|
84
|
-
// Keep: Required for RN built in Event Emitter Calls.
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
@ReactMethod
|
|
88
|
-
fun removeListeners(@Suppress("UNUSED_PARAMETER") count: Int?) {
|
|
89
|
-
// Keep: Required for RN built in Event Emitter Calls.
|
|
90
|
-
}
|
|
91
|
-
|
|
92
68
|
/**
|
|
93
69
|
* Single entry point for all Core operations.
|
|
94
70
|
* Routes method calls to the appropriate command via the shared command factory.
|
|
95
71
|
*/
|
|
96
|
-
@ReactMethod
|
|
97
72
|
fun executeCore(data: ReadableMap, promise: Promise) {
|
|
98
73
|
val handled = coreModule.execute(
|
|
99
74
|
ReactNativeMethodCall(data),
|
|
@@ -112,6 +87,6 @@ open class ScanditDataCaptureCoreModule(
|
|
|
112
87
|
private val coreModule: CoreModule
|
|
113
88
|
get() {
|
|
114
89
|
return serviceLocator.resolve(CoreModule::class.java.simpleName) as? CoreModule?
|
|
115
|
-
?: throw ModuleNotStartedError(
|
|
90
|
+
?: throw ModuleNotStartedError(NAME)
|
|
116
91
|
}
|
|
117
92
|
}
|
|
@@ -10,15 +10,11 @@ import com.facebook.react.bridge.NativeModule
|
|
|
10
10
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
11
11
|
import com.facebook.react.uimanager.ViewGroupManager
|
|
12
12
|
import com.facebook.react.uimanager.ViewManager
|
|
13
|
-
import com.scandit.datacapture.frameworks.core.CoreModule
|
|
14
|
-
import com.scandit.datacapture.frameworks.core.events.Emitter
|
|
15
13
|
import com.scandit.datacapture.frameworks.core.lifecycle.ActivityLifecycleDispatcher
|
|
16
14
|
import com.scandit.datacapture.frameworks.core.lifecycle.DefaultActivityLifecycle
|
|
17
15
|
import com.scandit.datacapture.frameworks.core.locator.DefaultServiceLocator
|
|
18
16
|
import com.scandit.datacapture.reactnative.core.ui.DataCaptureViewManager
|
|
19
|
-
import com.scandit.datacapture.reactnative.core.utils.ReactNativeEventEmitter
|
|
20
17
|
import java.util.concurrent.ConcurrentHashMap
|
|
21
|
-
import java.util.concurrent.locks.ReentrantLock
|
|
22
18
|
|
|
23
19
|
class ScanditDataCaptureCorePackage : ScanditReactPackageBase() {
|
|
24
20
|
private val serviceLocator = DefaultServiceLocator.getInstance()
|
|
@@ -48,9 +44,7 @@ class ScanditDataCaptureCorePackage : ScanditReactPackageBase() {
|
|
|
48
44
|
// Register to receive lifecycle events
|
|
49
45
|
reactContext.addLifecycleEventListener(lifecycleListener)
|
|
50
46
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
// Use legacy module for both architectures (Interop Layer)
|
|
47
|
+
// Module sets up its own shared CoreModule in init
|
|
54
48
|
return mutableListOf(
|
|
55
49
|
ScanditDataCaptureCoreModule(reactContext, serviceLocator, viewManagers)
|
|
56
50
|
)
|
|
@@ -73,20 +67,4 @@ class ScanditDataCaptureCorePackage : ScanditReactPackageBase() {
|
|
|
73
67
|
|
|
74
68
|
override fun getModuleClasses(): List<Class<out NativeModule>> =
|
|
75
69
|
listOf(ScanditDataCaptureCoreModule::class.java)
|
|
76
|
-
|
|
77
|
-
private fun setupSharedModule(reactContext: ReactApplicationContext) {
|
|
78
|
-
lock.lock()
|
|
79
|
-
try {
|
|
80
|
-
val eventEmitter: Emitter = ReactNativeEventEmitter(reactContext)
|
|
81
|
-
val coreModule = CoreModule.create(eventEmitter)
|
|
82
|
-
coreModule.onCreate(reactContext)
|
|
83
|
-
serviceLocator.register(coreModule)
|
|
84
|
-
} finally {
|
|
85
|
-
lock.unlock()
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
companion object {
|
|
90
|
-
private val lock: ReentrantLock = ReentrantLock()
|
|
91
|
-
}
|
|
92
70
|
}
|
|
@@ -20,9 +20,14 @@ import com.scandit.datacapture.frameworks.core.locator.ServiceLocator
|
|
|
20
20
|
import com.scandit.datacapture.reactnative.core.data.ViewCreationRequest
|
|
21
21
|
import com.scandit.datacapture.reactnative.core.utils.ReactNativeResult
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Base class containing shared logic for DataCaptureView management.
|
|
25
|
+
* Used by both legacy (Paper) and new (Fabric) architecture implementations.
|
|
26
|
+
*/
|
|
27
|
+
abstract class DataCaptureViewManagerBase(
|
|
28
|
+
protected val serviceLocator: ServiceLocator<FrameworkModule>,
|
|
25
29
|
) : ScanditViewGroupManager<FrameLayout>() {
|
|
30
|
+
|
|
26
31
|
override fun getName(): String = "RNTDataCaptureView"
|
|
27
32
|
|
|
28
33
|
private val cachedCreationRequests = mutableMapOf<Int, ViewCreationRequest>()
|
|
@@ -97,10 +102,10 @@ class DataCaptureViewManager(
|
|
|
97
102
|
}
|
|
98
103
|
}
|
|
99
104
|
|
|
100
|
-
|
|
105
|
+
protected val coreModule: CoreModule
|
|
101
106
|
get() {
|
|
102
107
|
return serviceLocator.resolve(CoreModule::class.java.simpleName) as? CoreModule?
|
|
103
|
-
?: throw ModuleNotStartedError(
|
|
108
|
+
?: throw ModuleNotStartedError(DataCaptureViewManagerBase::class.java.simpleName)
|
|
104
109
|
}
|
|
105
110
|
|
|
106
111
|
companion object {
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the Scandit Data Capture SDK
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2020- Scandit AG. All rights reserved.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
package com.scandit.datacapture.reactnative.core
|
|
8
|
+
|
|
9
|
+
import com.facebook.fbreact.specs.NativeScanditDataCaptureCoreSpec
|
|
10
|
+
import com.facebook.react.bridge.Promise
|
|
11
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
12
|
+
import com.facebook.react.bridge.ReadableMap
|
|
13
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
14
|
+
import com.facebook.react.uimanager.ViewGroupManager
|
|
15
|
+
import com.scandit.datacapture.frameworks.core.CoreModule
|
|
16
|
+
import com.scandit.datacapture.frameworks.core.FrameworkModule
|
|
17
|
+
import com.scandit.datacapture.frameworks.core.locator.ServiceLocator
|
|
18
|
+
import com.scandit.datacapture.reactnative.core.utils.ReactNativeEventEmitter
|
|
19
|
+
|
|
20
|
+
@ReactModule(name = ScanditDataCaptureCoreModuleBase.NAME)
|
|
21
|
+
class ScanditDataCaptureCoreModule(
|
|
22
|
+
reactContext: ReactApplicationContext,
|
|
23
|
+
private val serviceLocator: ServiceLocator<FrameworkModule>,
|
|
24
|
+
viewManagers: Map<String, ViewGroupManager<*>>,
|
|
25
|
+
) : NativeScanditDataCaptureCoreSpec(reactContext) {
|
|
26
|
+
|
|
27
|
+
private val moduleBase = ScanditDataCaptureCoreModuleBase(serviceLocator, viewManagers)
|
|
28
|
+
|
|
29
|
+
init {
|
|
30
|
+
// Set up the shared CoreModule with JSI-based event emitter
|
|
31
|
+
setupSharedModule(reactContext)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
companion object {
|
|
35
|
+
const val NAME = ScanditDataCaptureCoreModuleBase.NAME
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
override fun getName(): String = NAME
|
|
39
|
+
|
|
40
|
+
override fun getTypedExportedConstants(): MutableMap<String, Any> = moduleBase.getDefaults()
|
|
41
|
+
|
|
42
|
+
override fun invalidate() {
|
|
43
|
+
moduleBase.onInvalidate()
|
|
44
|
+
super.invalidate()
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private fun setupSharedModule(reactContext: ReactApplicationContext) {
|
|
48
|
+
// Check if CoreModule is already registered to avoid duplicate initialization
|
|
49
|
+
val existingModule = serviceLocator.resolve(CoreModule::class.java.simpleName)
|
|
50
|
+
if (existingModule != null) {
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Create emitter with JSI-based emit handler
|
|
55
|
+
val emitter = ReactNativeEventEmitter { payload ->
|
|
56
|
+
emitOnScanditEvent(payload)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
val coreModule = CoreModule.create(emitter)
|
|
60
|
+
coreModule.onCreate(reactContext)
|
|
61
|
+
serviceLocator.register(coreModule)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
override fun createDataCaptureView(data: ReadableMap, promise: Promise) =
|
|
65
|
+
moduleBase.createDataCaptureView(data, promise)
|
|
66
|
+
|
|
67
|
+
override fun removeDataCaptureView(data: ReadableMap, promise: Promise) =
|
|
68
|
+
moduleBase.removeDataCaptureView(promise)
|
|
69
|
+
|
|
70
|
+
override fun executeCore(data: ReadableMap, promise: Promise) =
|
|
71
|
+
moduleBase.executeCore(data, promise)
|
|
72
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* This file is part of the Scandit Data Capture SDK
|
|
3
3
|
*
|
|
4
|
-
* Copyright (C)
|
|
4
|
+
* Copyright (C) 2026- Scandit AG. All rights reserved.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
package com.scandit.datacapture.reactnative.core
|
|
@@ -17,12 +17,18 @@ import java.util.concurrent.ConcurrentHashMap
|
|
|
17
17
|
/**
|
|
18
18
|
* Base class for React Native packages in the new architecture.
|
|
19
19
|
*
|
|
20
|
-
*
|
|
21
|
-
* -
|
|
22
|
-
* -
|
|
23
|
-
*
|
|
24
|
-
* -
|
|
25
|
-
*
|
|
20
|
+
* Supports incremental TurboModule migration:
|
|
21
|
+
* - Modules extending Codegen specs (*Spec) → isTurboModule = true (JSI)
|
|
22
|
+
* - Legacy modules (ReactContextBaseJavaModule) → isTurboModule = false (Interop Layer)
|
|
23
|
+
*
|
|
24
|
+
* The isTurboModule flag is auto-detected by checking if the module's superclass
|
|
25
|
+
* name contains "Spec" (the Codegen naming convention).
|
|
26
|
+
*
|
|
27
|
+
* To migrate a module to TurboModule:
|
|
28
|
+
* 1. Create TypeScript spec: ts/NativeScanditDataCapture{Module}.ts
|
|
29
|
+
* 2. Add codegenConfig to package.json
|
|
30
|
+
* 3. Create newArch module extending the generated spec
|
|
31
|
+
* 4. The base class will automatically detect and use JSI
|
|
26
32
|
*/
|
|
27
33
|
abstract class ScanditReactPackageBase : TurboReactPackage() {
|
|
28
34
|
@Suppress("unused")
|
|
@@ -35,8 +41,14 @@ abstract class ScanditReactPackageBase : TurboReactPackage() {
|
|
|
35
41
|
// Get or create context-specific cache
|
|
36
42
|
val contextId = System.identityHashCode(reactContext).toString()
|
|
37
43
|
|
|
44
|
+
// Only clear cache if context changed and we have stale entries
|
|
45
|
+
synchronized(moduleCache) {
|
|
46
|
+
if (!moduleCache.containsKey(contextId) && moduleCache.isNotEmpty()) {
|
|
47
|
+
moduleCache.clear()
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
38
51
|
val contextCache = moduleCache.getOrPut(contextId) {
|
|
39
|
-
// Pre-populate cache with modules from createNativeModules()
|
|
40
52
|
val preCreatedModules = createNativeModules(reactContext)
|
|
41
53
|
val cache = ConcurrentHashMap<String, NativeModule>()
|
|
42
54
|
preCreatedModules.forEach { module ->
|
|
@@ -45,17 +57,38 @@ abstract class ScanditReactPackageBase : TurboReactPackage() {
|
|
|
45
57
|
cache
|
|
46
58
|
}
|
|
47
59
|
|
|
48
|
-
|
|
60
|
+
// Return cached module if available
|
|
61
|
+
val cachedModule = contextCache[name]
|
|
62
|
+
if (cachedModule != null) {
|
|
63
|
+
return cachedModule
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Fallback: recreate modules if not found (handles edge cases)
|
|
67
|
+
val preCreatedModules = createNativeModules(reactContext)
|
|
68
|
+
val module = preCreatedModules.find { it.name == name }
|
|
69
|
+
if (module != null) {
|
|
70
|
+
contextCache[name] = module
|
|
71
|
+
return module
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return null
|
|
49
75
|
}
|
|
50
76
|
|
|
51
77
|
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
|
|
52
78
|
return ReactModuleInfoProvider {
|
|
53
79
|
val moduleInfoMap = mutableMapOf<String, ReactModuleInfo>()
|
|
54
|
-
|
|
55
80
|
// Extract module info from @ReactModule annotations
|
|
56
81
|
getModuleClasses().forEach { moduleClass ->
|
|
57
82
|
val annotation = moduleClass.getAnnotation(ReactModule::class.java)
|
|
58
83
|
if (annotation != null) {
|
|
84
|
+
// Check if this is a TurboModule (extends generated spec base class)
|
|
85
|
+
val isTurboModule = try {
|
|
86
|
+
val superclass = moduleClass.superclass
|
|
87
|
+
superclass != null && superclass.name.contains("Spec")
|
|
88
|
+
} catch (e: Exception) {
|
|
89
|
+
false
|
|
90
|
+
}
|
|
91
|
+
|
|
59
92
|
moduleInfoMap[annotation.name] = ReactModuleInfo(
|
|
60
93
|
annotation.name,
|
|
61
94
|
className = moduleClass.name,
|
|
@@ -63,7 +96,7 @@ abstract class ScanditReactPackageBase : TurboReactPackage() {
|
|
|
63
96
|
needsEagerInit = true,
|
|
64
97
|
hasConstants = true,
|
|
65
98
|
isCxxModule = false,
|
|
66
|
-
isTurboModule =
|
|
99
|
+
isTurboModule = isTurboModule // true for codegen TurboModules
|
|
67
100
|
)
|
|
68
101
|
}
|
|
69
102
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the Scandit Data Capture SDK
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2026- Scandit AG. All rights reserved.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
package com.scandit.datacapture.reactnative.core.ui
|
|
8
|
+
|
|
9
|
+
import android.widget.FrameLayout
|
|
10
|
+
import com.facebook.react.uimanager.ViewManagerDelegate
|
|
11
|
+
import com.facebook.react.viewmanagers.RNTDataCaptureViewManagerDelegate
|
|
12
|
+
import com.facebook.react.viewmanagers.RNTDataCaptureViewManagerInterface
|
|
13
|
+
import com.scandit.datacapture.frameworks.core.FrameworkModule
|
|
14
|
+
import com.scandit.datacapture.frameworks.core.locator.ServiceLocator
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* New architecture (Fabric) view manager for DataCaptureView.
|
|
18
|
+
* Implements the Codegen-generated interface and uses the delegate pattern.
|
|
19
|
+
*/
|
|
20
|
+
class DataCaptureViewManager(
|
|
21
|
+
serviceLocator: ServiceLocator<FrameworkModule>,
|
|
22
|
+
) : DataCaptureViewManagerBase(serviceLocator),
|
|
23
|
+
RNTDataCaptureViewManagerInterface<FrameLayout> {
|
|
24
|
+
|
|
25
|
+
private val delegate = RNTDataCaptureViewManagerDelegate(this)
|
|
26
|
+
|
|
27
|
+
override fun getDelegate(): ViewManagerDelegate<FrameLayout> = delegate
|
|
28
|
+
|
|
29
|
+
// RNTDataCaptureViewManagerInterface methods
|
|
30
|
+
// Currently no custom props defined in the spec, but the interface must be implemented
|
|
31
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the Scandit Data Capture SDK
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2026- Scandit AG. All rights reserved.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
package com.scandit.datacapture.reactnative.core.utils
|
|
8
|
+
|
|
9
|
+
import com.facebook.react.bridge.Arguments
|
|
10
|
+
import com.facebook.react.bridge.ReadableMap
|
|
11
|
+
import com.scandit.datacapture.frameworks.core.events.Emitter
|
|
12
|
+
import org.json.JSONObject
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* New architecture event emitter that uses CodegenTypes.EventEmitter via JSI.
|
|
16
|
+
*
|
|
17
|
+
* This emitter accepts a lambda that calls the module's emitOnScanditEvent() method.
|
|
18
|
+
* The lambda is provided at construction time by the TurboModule.
|
|
19
|
+
*
|
|
20
|
+
* Example usage:
|
|
21
|
+
* ```
|
|
22
|
+
* val emitter = ReactNativeEventEmitter { payload -> emitOnScanditEvent(payload) }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
class ReactNativeEventEmitter(
|
|
26
|
+
private val emitHandler: (ReadableMap) -> Unit
|
|
27
|
+
) : Emitter {
|
|
28
|
+
|
|
29
|
+
override fun emit(eventName: String, payload: MutableMap<String, Any?>) {
|
|
30
|
+
val reactPayload = Arguments.createMap().apply {
|
|
31
|
+
putString("name", eventName)
|
|
32
|
+
putString("data", JSONObject(payload).toString())
|
|
33
|
+
// Extract viewId/modeId to top level for pre-parse filtering on JS side
|
|
34
|
+
payload["viewId"]?.let { putInt("viewId", it as Int) }
|
|
35
|
+
payload["modeId"]?.let { putInt("modeId", it as Int) }
|
|
36
|
+
}
|
|
37
|
+
emitHandler(reactPayload)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the Scandit Data Capture SDK
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2020- Scandit AG. All rights reserved.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
package com.scandit.datacapture.reactnative.core
|
|
8
|
+
|
|
9
|
+
import com.facebook.react.bridge.Promise
|
|
10
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
11
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
12
|
+
import com.facebook.react.bridge.ReactMethod
|
|
13
|
+
import com.facebook.react.bridge.ReadableMap
|
|
14
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
15
|
+
import com.facebook.react.uimanager.ViewGroupManager
|
|
16
|
+
import com.scandit.datacapture.frameworks.core.CoreModule
|
|
17
|
+
import com.scandit.datacapture.frameworks.core.FrameworkModule
|
|
18
|
+
import com.scandit.datacapture.frameworks.core.locator.ServiceLocator
|
|
19
|
+
import com.scandit.datacapture.reactnative.core.utils.ReactNativeEventEmitter
|
|
20
|
+
|
|
21
|
+
@ReactModule(name = ScanditDataCaptureCoreModuleBase.NAME)
|
|
22
|
+
class ScanditDataCaptureCoreModule(
|
|
23
|
+
reactContext: ReactApplicationContext,
|
|
24
|
+
private val serviceLocator: ServiceLocator<FrameworkModule>,
|
|
25
|
+
viewManagers: Map<String, ViewGroupManager<*>>,
|
|
26
|
+
) : ReactContextBaseJavaModule(reactContext) {
|
|
27
|
+
|
|
28
|
+
private val moduleBase = ScanditDataCaptureCoreModuleBase(serviceLocator, viewManagers)
|
|
29
|
+
|
|
30
|
+
init {
|
|
31
|
+
// Set up the shared CoreModule with bridge-based event emitter
|
|
32
|
+
setupSharedModule(reactContext)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
companion object {
|
|
36
|
+
const val NAME = ScanditDataCaptureCoreModuleBase.NAME
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
override fun getName(): String = NAME
|
|
40
|
+
|
|
41
|
+
override fun getConstants(): MutableMap<String, Any> = moduleBase.getDefaults()
|
|
42
|
+
|
|
43
|
+
override fun invalidate() {
|
|
44
|
+
moduleBase.onInvalidate()
|
|
45
|
+
super.invalidate()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private fun setupSharedModule(reactContext: ReactApplicationContext) {
|
|
49
|
+
// Check if CoreModule is already registered to avoid duplicate initialization
|
|
50
|
+
val existingModule = serviceLocator.resolve(CoreModule::class.java.simpleName)
|
|
51
|
+
if (existingModule != null) {
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Create emitter with bridge-based RCTDeviceEventEmitter
|
|
56
|
+
val emitter = ReactNativeEventEmitter(reactContext)
|
|
57
|
+
|
|
58
|
+
val coreModule = CoreModule.create(emitter)
|
|
59
|
+
coreModule.onCreate(reactContext)
|
|
60
|
+
serviceLocator.register(coreModule)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@ReactMethod
|
|
64
|
+
fun createDataCaptureView(readableMap: ReadableMap, promise: Promise) =
|
|
65
|
+
moduleBase.createDataCaptureView(readableMap, promise)
|
|
66
|
+
|
|
67
|
+
@ReactMethod
|
|
68
|
+
fun removeDataCaptureView(
|
|
69
|
+
@Suppress("unused") readableMap: ReadableMap,
|
|
70
|
+
promise: Promise
|
|
71
|
+
) = moduleBase.removeDataCaptureView(promise)
|
|
72
|
+
|
|
73
|
+
@ReactMethod
|
|
74
|
+
fun addListener(@Suppress("UNUSED_PARAMETER") eventName: String?) {
|
|
75
|
+
// Keep: Required for RN built in Event Emitter Calls.
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@ReactMethod
|
|
79
|
+
fun removeListeners(@Suppress("UNUSED_PARAMETER") count: Int?) {
|
|
80
|
+
// Keep: Required for RN built in Event Emitter Calls.
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
@ReactMethod
|
|
84
|
+
fun executeCore(data: ReadableMap, promise: Promise) =
|
|
85
|
+
moduleBase.executeCore(data, promise)
|
|
86
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* This file is part of the Scandit Data Capture SDK
|
|
3
3
|
*
|
|
4
|
-
* Copyright (C)
|
|
4
|
+
* Copyright (C) 2026- Scandit AG. All rights reserved.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
package com.scandit.datacapture.reactnative.core
|
|
@@ -15,6 +15,6 @@ abstract class ScanditReactPackageBase : ReactPackage {
|
|
|
15
15
|
|
|
16
16
|
@Suppress("EmptyFunctionBlock")
|
|
17
17
|
fun clearCache() {
|
|
18
|
-
// No-op
|
|
18
|
+
// No-op in old architecture - cache management not needed
|
|
19
19
|
}
|
|
20
20
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the Scandit Data Capture SDK
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2020- Scandit AG. All rights reserved.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
package com.scandit.datacapture.reactnative.core.ui
|
|
8
|
+
|
|
9
|
+
import com.scandit.datacapture.frameworks.core.FrameworkModule
|
|
10
|
+
import com.scandit.datacapture.frameworks.core.locator.ServiceLocator
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Legacy architecture (Paper) view manager for DataCaptureView.
|
|
14
|
+
* Extends the shared base class with no additional implementation needed.
|
|
15
|
+
*/
|
|
16
|
+
class DataCaptureViewManager(
|
|
17
|
+
serviceLocator: ServiceLocator<FrameworkModule>,
|
|
18
|
+
) : DataCaptureViewManagerBase(serviceLocator)
|