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
|
@@ -14,6 +14,40 @@ public let sdcSharedMethodQueue = DispatchQueue(
|
|
|
14
14
|
qos: .userInteractive
|
|
15
15
|
)
|
|
16
16
|
|
|
17
|
+
/// Helper class to expose the shared method queue to Objective-C.
|
|
18
|
+
@objc(SDCSharedMethodQueue)
|
|
19
|
+
public class SDCSharedMethodQueue: NSObject {
|
|
20
|
+
@objc public static var queue: DispatchQueue {
|
|
21
|
+
sdcSharedMethodQueue
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/// Factory class for creating ReactNativeEmitter instances.
|
|
26
|
+
/// This is needed because the ReactNativeEmitter initializer isn't properly exported
|
|
27
|
+
/// across Swift module boundaries due to the RCTEventEmitter parameter type.
|
|
28
|
+
@objcMembers
|
|
29
|
+
public class ReactNativeEmitterFactory: NSObject {
|
|
30
|
+
/// Creates a new ReactNativeEmitter with the given emitter.
|
|
31
|
+
/// - Parameter emitter: An RCTEventEmitter instance (passed as Any to work around module visibility issues).
|
|
32
|
+
/// - Returns: A new ReactNativeEmitter, or nil if the emitter is not an RCTEventEmitter.
|
|
33
|
+
public static func create(emitter: Any) -> ReactNativeEmitter? {
|
|
34
|
+
guard let rctEmitter = emitter as? RCTEventEmitter else {
|
|
35
|
+
return nil
|
|
36
|
+
}
|
|
37
|
+
return ReactNativeEmitter(emitter: rctEmitter)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/// Creates a new ReactNativeEmitter with both old and new architecture emitters.
|
|
41
|
+
/// - Parameters:
|
|
42
|
+
/// - emitter: An RCTEventEmitter instance (passed as Any to work around module visibility issues), can be nil in new arch.
|
|
43
|
+
/// - turboEmitter: Optional TurboModule emitter block for new architecture.
|
|
44
|
+
/// - Returns: A new ReactNativeEmitter.
|
|
45
|
+
public static func create(emitter: Any?, turboEmitter: SDCEventEmitBlock?) -> ReactNativeEmitter? {
|
|
46
|
+
let rctEmitter = emitter as? RCTEventEmitter
|
|
47
|
+
return ReactNativeEmitter(emitter: rctEmitter, turboEmitter: turboEmitter)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
17
51
|
enum ScanditDataCaptureCoreError: Int, CustomNSError {
|
|
18
52
|
case deserializationError = 1
|
|
19
53
|
case nilDataCaptureView
|
|
@@ -53,40 +87,21 @@ enum ScanditDataCaptureCoreError: Int, CustomNSError {
|
|
|
53
87
|
}
|
|
54
88
|
}
|
|
55
89
|
|
|
56
|
-
|
|
57
|
-
class
|
|
90
|
+
/// Swift implementation for the Core native module.
|
|
91
|
+
/// This class contains all business logic and is used by the Obj-C++ adapter (NativeScanditDataCaptureCore).
|
|
92
|
+
/// Following the Adapter Pattern from React Native's TurboModule Swift guide.
|
|
93
|
+
@objcMembers
|
|
94
|
+
public class ScanditDataCaptureCoreImpl: NSObject {
|
|
58
95
|
|
|
59
96
|
var coreModule: CoreModule!
|
|
60
97
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
as? RNTSDCDataCaptureViewManager
|
|
65
|
-
else {
|
|
66
|
-
fatalError("RNTSDCDataCaptureViewManager not registered in bridge")
|
|
67
|
-
}
|
|
68
|
-
return manager
|
|
69
|
-
}()
|
|
70
|
-
|
|
71
|
-
public override init() {
|
|
72
|
-
super.init()
|
|
73
|
-
let emitter = ReactNativeEmitter(emitter: self)
|
|
74
|
-
coreModule = CoreModule.create(emitter: emitter)
|
|
75
|
-
coreModule.didStart()
|
|
76
|
-
DefaultServiceLocator.shared.register(module: coreModule)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
static public func register(modeDeserializer: DataCaptureModeDeserializer) {
|
|
80
|
-
Deserializers.Factory.add(modeDeserializer)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
static public func unregister(modeDeserializer: DataCaptureModeDeserializer) {
|
|
84
|
-
Deserializers.Factory.remove(modeDeserializer)
|
|
85
|
-
}
|
|
98
|
+
/// Reference to the RCTEventEmitter (the Obj-C++ adapter).
|
|
99
|
+
/// Set by the adapter after initialization.
|
|
100
|
+
weak var emitter: RCTEventEmitter?
|
|
86
101
|
|
|
87
102
|
static var rntSDCComponentDeserializers: [DataCaptureComponentDeserializer] = []
|
|
88
103
|
internal var componentDeserializers: [DataCaptureComponentDeserializer] {
|
|
89
|
-
|
|
104
|
+
ScanditDataCaptureCoreImpl.rntSDCComponentDeserializers
|
|
90
105
|
}
|
|
91
106
|
|
|
92
107
|
internal var components: [DataCaptureComponent] = [] {
|
|
@@ -105,39 +120,78 @@ class ScanditDataCaptureCore: RCTEventEmitter {
|
|
|
105
120
|
|
|
106
121
|
internal var hasListeners = false
|
|
107
122
|
|
|
108
|
-
public override
|
|
109
|
-
|
|
123
|
+
public override init() {
|
|
124
|
+
super.init()
|
|
110
125
|
}
|
|
111
126
|
|
|
112
|
-
|
|
113
|
-
|
|
127
|
+
/// Called by the Obj-C++ adapter to set up the emitter reference and initialize the module.
|
|
128
|
+
/// Must be called on the main thread (ensured by requiresMainQueueSetup).
|
|
129
|
+
public func setup(with emitter: RCTEventEmitter) {
|
|
130
|
+
self.emitter = emitter
|
|
131
|
+
let reactEmitter = ReactNativeEmitter(emitter: emitter)
|
|
132
|
+
coreModule = CoreModule.create(emitter: reactEmitter)
|
|
133
|
+
coreModule.didStart()
|
|
134
|
+
DefaultServiceLocator.shared.register(module: coreModule)
|
|
135
|
+
|
|
136
|
+
// Eagerly initialize defaults on main thread.
|
|
137
|
+
// This prevents Main Thread Checker errors when getConstants() is called later
|
|
138
|
+
// from a background thread, since CoreDefaults creates UI components.
|
|
139
|
+
_ = coreModule.getDefaults()
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/// Called by the Obj-C++ adapter to set up the emitter reference and initialize the module (new architecture).
|
|
143
|
+
/// Must be called on the main thread (ensured by requiresMainQueueSetup).
|
|
144
|
+
/// - Parameters:
|
|
145
|
+
/// - emitter: The RCTEventEmitter (nil in new arch since we don't inherit from RCTEventEmitter).
|
|
146
|
+
/// - turboEmitter: TurboModule emitter block for new architecture.
|
|
147
|
+
@objc(setupWith:turboEmitter:)
|
|
148
|
+
public func setup(with emitter: RCTEventEmitter?, turboEmitter: SDCEventEmitBlock?) {
|
|
149
|
+
self.emitter = emitter
|
|
150
|
+
let reactEmitter = ReactNativeEmitter(emitter: emitter, turboEmitter: turboEmitter)
|
|
151
|
+
|
|
152
|
+
coreModule = CoreModule.create(emitter: reactEmitter)
|
|
153
|
+
coreModule.didStart()
|
|
154
|
+
DefaultServiceLocator.shared.register(module: coreModule)
|
|
155
|
+
|
|
156
|
+
// Eagerly initialize defaults on main thread.
|
|
157
|
+
// This prevents Main Thread Checker errors when getConstants() is called later
|
|
158
|
+
// from a background thread, since CoreDefaults creates UI components.
|
|
159
|
+
_ = coreModule.getDefaults()
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
static public func register(modeDeserializer: DataCaptureModeDeserializer) {
|
|
163
|
+
Deserializers.Factory.add(modeDeserializer)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
static public func unregister(modeDeserializer: DataCaptureModeDeserializer) {
|
|
167
|
+
Deserializers.Factory.remove(modeDeserializer)
|
|
114
168
|
}
|
|
115
169
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
170
|
+
/// Returns module constants (Defaults and Version).
|
|
171
|
+
public func getConstants() -> [AnyHashable: Any] {
|
|
172
|
+
guard let module = coreModule else {
|
|
173
|
+
return [:]
|
|
174
|
+
}
|
|
175
|
+
return [
|
|
176
|
+
"Defaults": module.getDefaults()
|
|
120
177
|
]
|
|
121
178
|
}
|
|
122
179
|
|
|
123
|
-
|
|
180
|
+
/// Returns the list of supported events.
|
|
181
|
+
public func supportedEvents() -> [String] {
|
|
124
182
|
ScanditFrameworksCoreEvent.allCases.map { $0.rawValue }
|
|
125
183
|
}
|
|
126
184
|
|
|
127
|
-
public
|
|
128
|
-
|
|
129
|
-
|
|
185
|
+
public func invalidate() {
|
|
186
|
+
if let module = coreModule {
|
|
187
|
+
module.didStop()
|
|
188
|
+
let className = String(describing: type(of: module))
|
|
189
|
+
DefaultServiceLocator.shared.remove(clazzName: className)
|
|
190
|
+
}
|
|
130
191
|
RNTSDCDataCaptureViewManager.containers.removeAll()
|
|
131
|
-
let className = String(describing: type(of: coreModule))
|
|
132
|
-
DefaultServiceLocator.shared.remove(clazzName: className)
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
deinit {
|
|
136
|
-
invalidate()
|
|
137
192
|
}
|
|
138
193
|
|
|
139
|
-
|
|
140
|
-
func createDataCaptureView(
|
|
194
|
+
public func createDataCaptureView(
|
|
141
195
|
data: [String: Any],
|
|
142
196
|
resolve: @escaping RCTPromiseResolveBlock,
|
|
143
197
|
reject: @escaping RCTPromiseRejectBlock
|
|
@@ -170,13 +224,19 @@ class ScanditDataCaptureCore: RCTEventEmitter {
|
|
|
170
224
|
|
|
171
225
|
// If we already have a container created for this view, we just add the view to the container. If not the
|
|
172
226
|
// ScanditDataCaptureViewManager will take care of adding the created view.
|
|
173
|
-
|
|
227
|
+
// Check Paper (legacy arch) containers first, then Fabric (new arch) containers.
|
|
228
|
+
let paperContainer = RNTSDCDataCaptureViewManager.containers.first {
|
|
174
229
|
$0.reactTag == NSNumber(value: viewId)
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
230
|
+
}
|
|
231
|
+
let fabricContainer = RCTFabricDataCaptureViewContainers.containers().first {
|
|
232
|
+
$0.tag == viewId
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if let container = paperContainer ?? fabricContainer {
|
|
236
|
+
let addViewToContainer = {
|
|
237
|
+
// Check if container already has a DataCaptureView (e.g., StrictMode calls twice)
|
|
238
|
+
let hasDataCaptureView = container.subviews.contains { $0 is DataCaptureView }
|
|
239
|
+
if hasDataCaptureView {
|
|
180
240
|
return
|
|
181
241
|
}
|
|
182
242
|
|
|
@@ -184,12 +244,23 @@ class ScanditDataCaptureCore: RCTEventEmitter {
|
|
|
184
244
|
dcView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
|
185
245
|
container.addSubview(dcView)
|
|
186
246
|
}
|
|
247
|
+
|
|
248
|
+
dispatchMain {
|
|
249
|
+
// Use postFrameSetAction for both Paper and Fabric to ensure consistent timing
|
|
250
|
+
// If frame is already set (not zero), add immediately. Otherwise, wait for layoutSubviews.
|
|
251
|
+
if !container.frame.equalTo(.zero) {
|
|
252
|
+
addViewToContainer()
|
|
253
|
+
} else {
|
|
254
|
+
container.postFrameSetAction = {
|
|
255
|
+
addViewToContainer()
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
187
259
|
}
|
|
188
260
|
}
|
|
189
261
|
}
|
|
190
262
|
|
|
191
|
-
|
|
192
|
-
func removeDataCaptureView(
|
|
263
|
+
public func removeDataCaptureView(
|
|
193
264
|
data: [String: Any],
|
|
194
265
|
resolve: @escaping RCTPromiseResolveBlock,
|
|
195
266
|
reject: @escaping RCTPromiseRejectBlock
|
|
@@ -200,17 +271,20 @@ class ScanditDataCaptureCore: RCTEventEmitter {
|
|
|
200
271
|
|
|
201
272
|
/// Single entry point for all Core operations.
|
|
202
273
|
/// Routes method calls to the appropriate command via the shared command factory.
|
|
203
|
-
|
|
204
|
-
func executeCore(
|
|
274
|
+
public func executeCore(
|
|
205
275
|
_ data: [String: Any],
|
|
206
276
|
resolve: @escaping RCTPromiseResolveBlock,
|
|
207
277
|
reject: @escaping RCTPromiseRejectBlock
|
|
208
278
|
) {
|
|
279
|
+
guard let module = coreModule else {
|
|
280
|
+
reject("MODULE_NOT_INITIALIZED", "CoreModule is not initialized. setup() may not have been called.", nil)
|
|
281
|
+
return
|
|
282
|
+
}
|
|
209
283
|
let result = ReactNativeResult(resolve, reject)
|
|
210
|
-
let handled =
|
|
284
|
+
let handled = module.execute(
|
|
211
285
|
ReactNativeMethodCall(data),
|
|
212
286
|
result: result,
|
|
213
|
-
module:
|
|
287
|
+
module: module
|
|
214
288
|
)
|
|
215
289
|
if !handled {
|
|
216
290
|
let methodName = data["methodName"] as? String ?? "unknown"
|
|
@@ -0,0 +1,129 @@
|
|
|
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
|
+
import Foundation
|
|
8
|
+
import ScanditFrameworksCore
|
|
9
|
+
|
|
10
|
+
/// A protocol that allows different architecture implementations to manage containers.
|
|
11
|
+
public protocol DataCaptureViewContainerManager: AnyObject {
|
|
12
|
+
static var containers: [DataCaptureViewContainerWrapper] { get set }
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/// A shared wrapper view that hosts the native DataCaptureView.
|
|
16
|
+
/// Used by both legacy (Paper) and new (Fabric) architecture implementations.
|
|
17
|
+
@objc
|
|
18
|
+
@objcMembers
|
|
19
|
+
open class DataCaptureViewContainerWrapper: UIView {
|
|
20
|
+
|
|
21
|
+
/// The container manager that handles lifecycle notifications.
|
|
22
|
+
/// Set by the concrete architecture implementation.
|
|
23
|
+
public var containerManager: (any DataCaptureViewContainerManager.Type)?
|
|
24
|
+
|
|
25
|
+
/// Action to execute once the frame is set (when layoutSubviews is called with non-zero frame).
|
|
26
|
+
/// This ensures the container is ready before adding subviews.
|
|
27
|
+
/// The action is automatically cleared after execution.
|
|
28
|
+
public var postFrameSetAction: (() -> Void)?
|
|
29
|
+
|
|
30
|
+
/// Tracks whether the frame has been set to a non-zero value.
|
|
31
|
+
var isFrameSet: Bool = false
|
|
32
|
+
|
|
33
|
+
public override func layoutSubviews() {
|
|
34
|
+
super.layoutSubviews()
|
|
35
|
+
if !frame.equalTo(.zero) && !isFrameSet {
|
|
36
|
+
isFrameSet = true
|
|
37
|
+
if let action = postFrameSetAction {
|
|
38
|
+
postFrameSetAction = nil
|
|
39
|
+
action()
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public override func removeFromSuperview() {
|
|
45
|
+
if let manager = containerManager,
|
|
46
|
+
let index = manager.containers.firstIndex(where: { $0 === self })
|
|
47
|
+
{
|
|
48
|
+
dispatchMain {
|
|
49
|
+
manager.containers.remove(at: index)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if let droppedView = self.findFirstSubview(ofType: DataCaptureView.self) {
|
|
53
|
+
DeserializationLifeCycleDispatcher.shared.dispatchDataCaptureViewRemoved(view: droppedView)
|
|
54
|
+
}
|
|
55
|
+
super.removeFromSuperview()
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/// Called before a Fabric view is recycled for reuse.
|
|
59
|
+
/// Removes all hosted subviews and resets internal state so the recycled container
|
|
60
|
+
/// is ready to host a new view. If a DataCaptureView is present, notifies the
|
|
61
|
+
/// framework so that the associated FrameworksDataCaptureView is properly disposed.
|
|
62
|
+
@objc open func cleanupForRecycle() {
|
|
63
|
+
if let dcView = self.findFirstSubview(ofType: DataCaptureView.self) {
|
|
64
|
+
DeserializationLifeCycleDispatcher.shared.dispatchDataCaptureViewRemoved(view: dcView)
|
|
65
|
+
}
|
|
66
|
+
for subview in subviews {
|
|
67
|
+
subview.removeFromSuperview()
|
|
68
|
+
}
|
|
69
|
+
isFrameSet = false
|
|
70
|
+
postFrameSetAction = nil
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public func findFirstSubview<T: UIView>(ofType type: T.Type) -> T? {
|
|
74
|
+
self.subviews.first { $0 is T } as? T
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public override func didMoveToSuperview() {
|
|
78
|
+
super.didMoveToSuperview()
|
|
79
|
+
if self.findFirstSubview(ofType: DataCaptureView.self) == nil {
|
|
80
|
+
if !frame.equalTo(.zero) {
|
|
81
|
+
attachDataCaptureViewIfAvailable()
|
|
82
|
+
} else {
|
|
83
|
+
postFrameSetAction = { [weak self] in
|
|
84
|
+
self?.attachDataCaptureViewIfAvailable()
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/// Attaches the DataCaptureView to this container if one has been created.
|
|
91
|
+
/// Called when the container is added to the superview hierarchy.
|
|
92
|
+
public func attachDataCaptureViewIfAvailable() {
|
|
93
|
+
let viewId = getViewId()
|
|
94
|
+
guard viewId != 0 else { return }
|
|
95
|
+
|
|
96
|
+
if let frameworksDataCaptureView = DataCaptureViewHandler.shared.getView(viewId) {
|
|
97
|
+
guard let currentView = frameworksDataCaptureView.view else {
|
|
98
|
+
return
|
|
99
|
+
}
|
|
100
|
+
currentView.frame = self.bounds
|
|
101
|
+
currentView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
|
102
|
+
self.addSubview(currentView)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/// Returns the view ID used to look up the DataCaptureView.
|
|
107
|
+
/// Override in subclasses to provide architecture-specific ID retrieval.
|
|
108
|
+
@objc open func getViewId() -> Int {
|
|
109
|
+
0
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/// Fabric architecture (New Arch) wrapper for DataCaptureView.
|
|
114
|
+
/// Uses tag for view identification (Fabric doesn't have reactTag).
|
|
115
|
+
@objc(RCTFabricDataCaptureViewWrapper)
|
|
116
|
+
open class RCTFabricDataCaptureViewWrapper: DataCaptureViewContainerWrapper {
|
|
117
|
+
|
|
118
|
+
@objc open override func getViewId() -> Int {
|
|
119
|
+
self.tag
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
public override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
|
|
123
|
+
let view = super.hitTest(point, with: event)
|
|
124
|
+
if view === self {
|
|
125
|
+
return nil
|
|
126
|
+
}
|
|
127
|
+
return view
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the Scandit Data Capture SDK
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2026- Scandit AG. All rights reserved.
|
|
5
|
+
*/
|
|
6
|
+
|
|
2
7
|
import React_RCTAppDelegate
|
|
3
|
-
#endif
|
|
4
8
|
|
|
5
9
|
/// Protocol for AppDelegates that expose a React Native factory (RN 0.78+)
|
|
6
10
|
/// Implement this protocol to allow Scandit SDK to access your RCTReactNativeFactory
|
|
@@ -10,7 +14,7 @@ public protocol ScanditReactNativeFactoryContainer {
|
|
|
10
14
|
/// The React Native factory object (RN 0.78+)
|
|
11
15
|
/// Return your RCTReactNativeFactory instance here.
|
|
12
16
|
var reactNativeFactory: RCTReactNativeFactory? { get }
|
|
13
|
-
#
|
|
17
|
+
#else
|
|
14
18
|
/// The React Native factory object.
|
|
15
19
|
/// For RN versions before 0.78, return the object that has a `rootViewFactory` property.
|
|
16
20
|
var reactNativeFactory: AnyObject? { get }
|
|
@@ -39,7 +39,7 @@ public class CallbackLock<ResultType> {
|
|
|
39
39
|
condition.lock()
|
|
40
40
|
while !isCallbackFinished {
|
|
41
41
|
if !condition.wait(until: timeoutDate) {
|
|
42
|
-
|
|
42
|
+
SDCLogger.warn("Waited for \(name) to finish for \(timeout) seconds")
|
|
43
43
|
isCallbackFinished = true
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -7,17 +7,33 @@
|
|
|
7
7
|
import React
|
|
8
8
|
import ScanditFrameworksCore
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
/// Event emitter that supports both old and new React Native architectures.
|
|
11
|
+
///
|
|
12
|
+
/// Old architecture: Uses RCTEventEmitter.sendEvent
|
|
13
|
+
/// New architecture: Uses the generated spec base class's emitOnScanditEvent method
|
|
14
|
+
///
|
|
15
|
+
/// This mirrors Android's ReactNativeEventEmitter which accepts a lambda that calls
|
|
16
|
+
/// the module's emit method.
|
|
17
|
+
@objcMembers
|
|
18
|
+
open class ReactNativeEmitter: NSObject, Emitter {
|
|
19
|
+
public weak var emitter: RCTEventEmitter?
|
|
20
|
+
private var turboEmitter: SDCEventEmitBlock?
|
|
15
21
|
|
|
16
|
-
|
|
17
|
-
|
|
22
|
+
/// Creates a new ReactNativeEmitter with the given RCTEventEmitter.
|
|
23
|
+
/// - Parameter emitter: The RCTEventEmitter to use for sending events (old architecture).
|
|
24
|
+
public init(emitter: RCTEventEmitter?) {
|
|
25
|
+
self.emitter = emitter
|
|
26
|
+
super.init()
|
|
27
|
+
}
|
|
18
28
|
|
|
19
|
-
|
|
29
|
+
/// Creates a new ReactNativeEmitter with both old and new architecture emitters.
|
|
30
|
+
/// - Parameters:
|
|
31
|
+
/// - emitter: The RCTEventEmitter to use for old architecture (can be nil in new arch).
|
|
32
|
+
/// - turboEmitter: The TurboModule emitter block for new architecture.
|
|
33
|
+
public init(emitter: RCTEventEmitter?, turboEmitter: SDCEventEmitBlock?) {
|
|
20
34
|
self.emitter = emitter
|
|
35
|
+
self.turboEmitter = turboEmitter
|
|
36
|
+
super.init()
|
|
21
37
|
}
|
|
22
38
|
|
|
23
39
|
public func emit(name: String, payload: [String: Any?]) {
|
|
@@ -25,12 +41,29 @@ public class ReactNativeEmitter: ReactNativeEmitting {
|
|
|
25
41
|
let jsonString = String(data: data, encoding: .utf8)
|
|
26
42
|
else { return }
|
|
27
43
|
|
|
28
|
-
|
|
44
|
+
// Build the payload matching the spec's ScanditEventPayload type
|
|
45
|
+
var reactPayload: [String: Any] = [
|
|
29
46
|
"name": name,
|
|
30
47
|
"data": jsonString,
|
|
31
48
|
]
|
|
32
49
|
|
|
33
|
-
|
|
50
|
+
// Extract viewId/modeId to top level for pre-parse filtering on JS side
|
|
51
|
+
if let viewId = payload["viewId"] as? Int {
|
|
52
|
+
reactPayload["viewId"] = viewId
|
|
53
|
+
}
|
|
54
|
+
if let modeId = payload["modeId"] as? Int {
|
|
55
|
+
reactPayload["modeId"] = modeId
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// New architecture: use the TurboModule emitter block
|
|
59
|
+
if let turboEmitter = self.turboEmitter {
|
|
60
|
+
// Convert [String: Any] to [AnyHashable: Any] for the block parameter
|
|
61
|
+
let payload = reactPayload as [AnyHashable: Any]
|
|
62
|
+
turboEmitter(payload)
|
|
63
|
+
} else {
|
|
64
|
+
// Old architecture: use RCTEventEmitter.sendEvent
|
|
65
|
+
emitter?.sendEvent(withName: name, body: reactPayload)
|
|
66
|
+
}
|
|
34
67
|
}
|
|
35
68
|
|
|
36
69
|
public func hasListener(for event: String) -> Bool {
|
|
@@ -0,0 +1,22 @@
|
|
|
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: GenerateComponentDescriptorCpp.js
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#include "ComponentDescriptors.h"
|
|
12
|
+
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
|
13
|
+
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
|
|
14
|
+
|
|
15
|
+
namespace facebook::react {
|
|
16
|
+
|
|
17
|
+
void ScanditReactNativeDatacaptureCoreSpec_registerComponentDescriptorsFromCodegen(
|
|
18
|
+
std::shared_ptr<const ComponentDescriptorProviderRegistry> registry) {
|
|
19
|
+
registry->add(concreteComponentDescriptorProvider<RNTDataCaptureViewComponentDescriptor>());
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,24 @@
|
|
|
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: GenerateComponentDescriptorH.js
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#pragma once
|
|
12
|
+
|
|
13
|
+
#include "ShadowNodes.h"
|
|
14
|
+
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
|
15
|
+
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
|
|
16
|
+
|
|
17
|
+
namespace facebook::react {
|
|
18
|
+
|
|
19
|
+
using RNTDataCaptureViewComponentDescriptor = ConcreteComponentDescriptor<RNTDataCaptureViewShadowNode>;
|
|
20
|
+
|
|
21
|
+
void ScanditReactNativeDatacaptureCoreSpec_registerComponentDescriptorsFromCodegen(
|
|
22
|
+
std::shared_ptr<const ComponentDescriptorProviderRegistry> registry);
|
|
23
|
+
|
|
24
|
+
} // 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: GenerateEventEmitterCpp.js
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#include "EventEmitters.h"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
namespace facebook::react {
|
|
15
|
+
|
|
16
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,23 @@
|
|
|
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: GenerateEventEmitterH.js
|
|
9
|
+
*/
|
|
10
|
+
#pragma once
|
|
11
|
+
|
|
12
|
+
#include <react/renderer/components/view/ViewEventEmitter.h>
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
namespace facebook::react {
|
|
16
|
+
class RNTDataCaptureViewEventEmitter : public ViewEventEmitter {
|
|
17
|
+
public:
|
|
18
|
+
using ViewEventEmitter::ViewEventEmitter;
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
};
|
|
23
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,25 @@
|
|
|
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: GeneratePropsCpp.js
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#include "Props.h"
|
|
12
|
+
#include <react/renderer/core/PropsParserContext.h>
|
|
13
|
+
#include <react/renderer/core/propsConversions.h>
|
|
14
|
+
|
|
15
|
+
namespace facebook::react {
|
|
16
|
+
|
|
17
|
+
RNTDataCaptureViewProps::RNTDataCaptureViewProps(
|
|
18
|
+
const PropsParserContext &context,
|
|
19
|
+
const RNTDataCaptureViewProps &sourceProps,
|
|
20
|
+
const RawProps &rawProps): ViewProps(context, sourceProps, rawProps)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
{}
|
|
24
|
+
|
|
25
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,27 @@
|
|
|
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: GeneratePropsH.js
|
|
9
|
+
*/
|
|
10
|
+
#pragma once
|
|
11
|
+
|
|
12
|
+
#include <react/renderer/components/view/ViewProps.h>
|
|
13
|
+
#include <react/renderer/core/PropsParserContext.h>
|
|
14
|
+
|
|
15
|
+
namespace facebook::react {
|
|
16
|
+
|
|
17
|
+
class RNTDataCaptureViewProps final : public ViewProps {
|
|
18
|
+
public:
|
|
19
|
+
RNTDataCaptureViewProps() = default;
|
|
20
|
+
RNTDataCaptureViewProps(const PropsParserContext& context, const RNTDataCaptureViewProps &sourceProps, const RawProps &rawProps);
|
|
21
|
+
|
|
22
|
+
#pragma mark - Props
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,20 @@
|
|
|
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: GenerateComponentHObjCpp.js
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
#import <Foundation/Foundation.h>
|
|
11
|
+
#import <React/RCTDefines.h>
|
|
12
|
+
#import <React/RCTLog.h>
|
|
13
|
+
|
|
14
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
15
|
+
|
|
16
|
+
@protocol RCTRNTDataCaptureViewViewProtocol <NSObject>
|
|
17
|
+
|
|
18
|
+
@end
|
|
19
|
+
|
|
20
|
+
NS_ASSUME_NONNULL_END
|