scandit-react-native-datacapture-core 6.10.1 → 6.11.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.
Files changed (37) hide show
  1. package/THIRD_PARTY.txt +73 -0
  2. package/THIRD_PARTY_OCR.txt +452 -0
  3. package/android/build.gradle +5 -13
  4. package/android/src/main/kotlin/com/scandit/datacapture/reactnative/core/RnViewsOnUiThread.kt +8 -7
  5. package/android/src/main/kotlin/com/scandit/datacapture/reactnative/core/ScanditDataCaptureCoreModule.kt +81 -57
  6. package/android/src/main/kotlin/com/scandit/datacapture/reactnative/core/data/defaults/SerializableBrushDefaults.kt +3 -3
  7. package/android/src/main/kotlin/com/scandit/datacapture/reactnative/core/data/defaults/SerializableCameraDefaults.kt +6 -3
  8. package/android/src/main/kotlin/com/scandit/datacapture/reactnative/core/data/defaults/SerializableCameraSettingsDefaults.kt +6 -6
  9. package/android/src/main/kotlin/com/scandit/datacapture/reactnative/core/data/defaults/SerializableLaserlineViewfinderDefaults.kt +2 -1
  10. package/android/src/main/kotlin/com/scandit/datacapture/reactnative/core/data/defaults/SerializableRectangularViewfinderDefaults.kt +21 -14
  11. package/android/src/main/kotlin/com/scandit/datacapture/reactnative/core/deserializers/Deserializers.kt +17 -17
  12. package/android/src/main/kotlin/com/scandit/datacapture/reactnative/core/deserializers/TreeLifecycleObserver.kt +5 -5
  13. package/android/src/main/kotlin/com/scandit/datacapture/reactnative/core/listener/RCTDataCaptureContextListener.kt +2 -2
  14. package/android/src/main/kotlin/com/scandit/datacapture/reactnative/core/listener/RCTDataCaptureViewListener.kt +12 -6
  15. package/android/src/main/kotlin/com/scandit/datacapture/reactnative/core/ui/DataCaptureViewManager.kt +7 -4
  16. package/android/src/main/kotlin/com/scandit/datacapture/reactnative/core/utils/Extensions.kt +5 -5
  17. package/android/src/main/kotlin/com/scandit/datacapture/reactnative/core/utils/TestUtils.kt +1 -16
  18. package/ios/Sources/ScanditDataCaptureCore+Defaults.swift +2 -0
  19. package/ios/Sources/ScanditDataCaptureCore.m +4 -0
  20. package/ios/Sources/ScanditDataCaptureCore.swift +16 -0
  21. package/js/Camera+Related.d.ts +12 -0
  22. package/js/Camera+Related.js +28 -1
  23. package/js/Camera+Related.js.map +1 -1
  24. package/js/DataCaptureVersion.js +1 -1
  25. package/js/Viewfinder.d.ts +10 -2
  26. package/js/Viewfinder.js +43 -2
  27. package/js/Viewfinder.js.map +1 -1
  28. package/js/native/CameraProxy.d.ts +2 -0
  29. package/js/native/CameraProxy.js +6 -0
  30. package/js/native/CameraProxy.js.map +1 -1
  31. package/js/private/Defaults.js +4 -3
  32. package/js/private/Defaults.js.map +1 -1
  33. package/js/private/PrivateCamera+Related.d.ts +22 -1
  34. package/js/private/PrivateCamera+Related.js +34 -0
  35. package/js/private/PrivateCamera+Related.js.map +1 -1
  36. package/package.json +2 -2
  37. package/scandit-react-native-datacapture-core.podspec +1 -1
@@ -17,6 +17,8 @@ import com.scandit.datacapture.core.capture.DataCaptureContextListener
17
17
  import com.scandit.datacapture.core.capture.DataCaptureVersion
18
18
  import com.scandit.datacapture.core.common.feedback.Feedback
19
19
  import com.scandit.datacapture.core.common.geometry.*
20
+ import com.scandit.datacapture.core.data.FrameData
21
+ import com.scandit.datacapture.core.data.toJson
20
22
  import com.scandit.datacapture.core.json.JsonValue
21
23
  import com.scandit.datacapture.core.source.*
22
24
  import com.scandit.datacapture.core.source.serialization.FrameSourceDeserializer
@@ -45,15 +47,15 @@ class ScanditDataCaptureCoreModule(
45
47
  private val reactContext: ReactApplicationContext,
46
48
  eventEmitter: RCTDeviceEventEmitter = LazyEventEmitter(reactContext),
47
49
  private val dataCaptureContextListener: RCTDataCaptureContextListener =
48
- RCTDataCaptureContextListener(eventEmitter),
50
+ RCTDataCaptureContextListener(eventEmitter),
49
51
  private val frameSourceListener: RCTFrameSourceListener = RCTFrameSourceListener(eventEmitter),
50
52
  private val dataCaptureViewListener: RCTDataCaptureViewListener =
51
- RCTDataCaptureViewListener(eventEmitter)
53
+ RCTDataCaptureViewListener(eventEmitter)
52
54
  ) : ReactContextBaseJavaModule(reactContext),
53
- FrameSourceDeserializerListener,
54
- DataCaptureContextListener by dataCaptureContextListener,
55
- FrameSourceListener by frameSourceListener,
56
- DataCaptureViewListener by dataCaptureViewListener {
55
+ FrameSourceDeserializerListener,
56
+ DataCaptureContextListener by dataCaptureContextListener,
57
+ FrameSourceListener by frameSourceListener,
58
+ DataCaptureViewListener by dataCaptureViewListener {
57
59
 
58
60
  companion object {
59
61
  private const val VERSION_KEY = "Version"
@@ -62,8 +64,14 @@ class ScanditDataCaptureCoreModule(
62
64
  private val ERROR_DESERIALIZATION_FAILED = Error(1, "Unable to deserialize a valid object.")
63
65
  private val ERROR_NULL_VIEW = Error(2, "DataCaptureView is null")
64
66
  private val ERROR_CAMERA_NOT_READY = Error(3, "Camera has yet not been instantiated.")
65
- private val ERROR_WRONG_CAMERA_POSITION = Error(4, "CameraPosition argument does not " +
66
- "match the position of the currently used camera.")
67
+ private val ERROR_WRONG_CAMERA_POSITION = Error(
68
+ 4,
69
+ "CameraPosition argument does not " +
70
+ "match the position of the currently used camera."
71
+ )
72
+ private val ERROR_NULL_FRAME = Error(5, "Frame is null, it might've been reused already.")
73
+
74
+ var lastFrame: FrameData? = null
67
75
  }
68
76
 
69
77
  @get:VisibleForTesting
@@ -91,39 +99,39 @@ class ScanditDataCaptureCoreModule(
91
99
  val aimerViewfinder = AimerViewfinder()
92
100
  val brush = Brush.transparent()
93
101
  val availableCameraPositions = listOfNotNull(
94
- Camera.getCamera(CameraPosition.USER_FACING)?.position,
95
- Camera.getCamera(CameraPosition.WORLD_FACING)?.position
102
+ Camera.getCamera(CameraPosition.USER_FACING)?.position,
103
+ Camera.getCamera(CameraPosition.WORLD_FACING)?.position
96
104
  )
97
105
 
98
106
  SerializableCoreDefaults(
99
- deviceId = DataCaptureContext.DEVICE_ID,
100
- cameraDefaults = SerializableCameraDefaults(
101
- cameraSettingsDefaults = SerializableCameraSettingsDefaults(
102
- settings = cameraSettings
103
- ),
104
- availablePositions = availableCameraPositions,
105
- defaultPosition = Camera.getDefaultCamera()?.position?.toJson()
106
- ),
107
- dataCaptureViewDefaults = SerializableDataCaptureViewDefaults(dataCaptureView),
108
- laserlineViewfinderDefaults = SerializableLaserlineViewfinderDefaults(
109
- laserViewfinder
110
- ),
111
- rectangularViewfinderDefaults = SerializableRectangularViewfinderDefaults(
112
- rectangularViewfinder
113
- ),
114
- spotlightViewfinderDefaults = SerializableSpotlightViewfinderDefaults(
115
- size = spotlightViewfinder.sizeWithUnitAndAspect.toJson(),
116
- enabledBorderColor = spotlightViewfinder.enabledBorderColor.hexString,
117
- disabledBorderColor = spotlightViewfinder.disabledBorderColor.hexString,
118
- backgroundColor = spotlightViewfinder.backgroundColor.hexString
107
+ deviceId = DataCaptureContext.DEVICE_ID,
108
+ cameraDefaults = SerializableCameraDefaults(
109
+ cameraSettingsDefaults = SerializableCameraSettingsDefaults(
110
+ settings = cameraSettings
119
111
  ),
120
- aimerViewfinderDefaults = SerializableAimerViewfinderDefaults(
121
- frameColor = aimerViewfinder.frameColor.hexString,
122
- dotColor = aimerViewfinder.dotColor.hexString
123
- ),
124
- brushDefaults = SerializableBrushDefaults(
125
- brush = brush
126
- )
112
+ availablePositions = availableCameraPositions,
113
+ defaultPosition = Camera.getDefaultCamera()?.position?.toJson()
114
+ ),
115
+ dataCaptureViewDefaults = SerializableDataCaptureViewDefaults(dataCaptureView),
116
+ laserlineViewfinderDefaults = SerializableLaserlineViewfinderDefaults(
117
+ laserViewfinder
118
+ ),
119
+ rectangularViewfinderDefaults = SerializableRectangularViewfinderDefaults(
120
+ rectangularViewfinder
121
+ ),
122
+ spotlightViewfinderDefaults = SerializableSpotlightViewfinderDefaults(
123
+ size = spotlightViewfinder.sizeWithUnitAndAspect.toJson(),
124
+ enabledBorderColor = spotlightViewfinder.enabledBorderColor.hexString,
125
+ disabledBorderColor = spotlightViewfinder.disabledBorderColor.hexString,
126
+ backgroundColor = spotlightViewfinder.backgroundColor.hexString
127
+ ),
128
+ aimerViewfinderDefaults = SerializableAimerViewfinderDefaults(
129
+ frameColor = aimerViewfinder.frameColor.hexString,
130
+ dotColor = aimerViewfinder.dotColor.hexString
131
+ ),
132
+ brushDefaults = SerializableBrushDefaults(
133
+ brush = brush
134
+ )
127
135
  )
128
136
  }
129
137
 
@@ -138,8 +146,8 @@ class ScanditDataCaptureCoreModule(
138
146
  override fun getName(): String = "ScanditDataCaptureCore"
139
147
 
140
148
  override fun getConstants(): MutableMap<String, Any> = mutableMapOf(
141
- VERSION_KEY to DataCaptureVersion.VERSION_STRING,
142
- DEFAULTS_KEY to defaults.toWritableMap()
149
+ VERSION_KEY to DataCaptureVersion.VERSION_STRING,
150
+ DEFAULTS_KEY to defaults.toWritableMap()
143
151
  )
144
152
 
145
153
  @ReactMethod
@@ -205,10 +213,10 @@ class ScanditDataCaptureCoreModule(
205
213
  TreeLifecycleObserver.dispatchParsersRemoved()
206
214
 
207
215
  val result = deserializers.dataCaptureContextDeserializer.updateContextFromJson(
208
- dataCaptureContext,
209
- DataCaptureViewHandler.dataCaptureView,
210
- emptyList(),
211
- newJson
216
+ dataCaptureContext,
217
+ DataCaptureViewHandler.dataCaptureView,
218
+ emptyList(),
219
+ newJson
212
220
  )
213
221
 
214
222
  DataCaptureViewHandler.dataCaptureView?.removeListener(this)
@@ -226,6 +234,18 @@ class ScanditDataCaptureCoreModule(
226
234
  contextFromJSON(json, promise)
227
235
  }
228
236
 
237
+ @ReactMethod
238
+ fun getLastFrame(promise: Promise) {
239
+ val lastFrame = ScanditDataCaptureCoreModule.lastFrame
240
+
241
+ if (lastFrame == null) {
242
+ promise.reject(ERROR_NULL_FRAME)
243
+ return
244
+ }
245
+
246
+ promise.resolve(lastFrame.toJson())
247
+ }
248
+
229
249
  @ReactMethod
230
250
  fun dispose() {
231
251
  TreeLifecycleObserver.dispatchTreeDestroyed()
@@ -263,10 +283,11 @@ class ScanditDataCaptureCoreModule(
263
283
 
264
284
  try {
265
285
  val mappedPoint = view.mapFramePointToView(
266
- PointDeserializer.fromJson(json)
286
+ PointDeserializer.fromJson(json)
267
287
  ).densityIndependent
268
288
  promise.resolve(mappedPoint.toJson())
269
289
  } catch (e: JSONException) {
290
+ println(e)
270
291
  promise.reject(ERROR_DESERIALIZATION_FAILED)
271
292
  }
272
293
  }
@@ -280,20 +301,21 @@ class ScanditDataCaptureCoreModule(
280
301
 
281
302
  try {
282
303
  val mappedQuadrilateral = view.mapFrameQuadrilateralToView(
283
- QuadrilateralDeserializer.fromJson(json)
304
+ QuadrilateralDeserializer.fromJson(json)
284
305
  ).densityIndependent
285
306
  promise.resolve(mappedQuadrilateral.toJson())
286
307
  } catch (e: JSONException) {
308
+ println(e)
287
309
  promise.reject(ERROR_DESERIALIZATION_FAILED)
288
310
  }
289
311
  }
290
312
 
291
313
  private val Quadrilateral.densityIndependent: Quadrilateral
292
314
  get() = Quadrilateral(
293
- topLeft.densityIndependent,
294
- topRight.densityIndependent,
295
- bottomRight.densityIndependent,
296
- bottomLeft.densityIndependent
315
+ topLeft.densityIndependent,
316
+ topRight.densityIndependent,
317
+ bottomRight.densityIndependent,
318
+ bottomLeft.densityIndependent
297
319
  )
298
320
 
299
321
  private val Point.densityIndependent: Point
@@ -307,11 +329,11 @@ class ScanditDataCaptureCoreModule(
307
329
  try {
308
330
  @Suppress("UseCheckOrError") // Explicit exception for readability.
309
331
  camera
310
- ?.takeIf { it.position == CameraPositionDeserializer.fromJson(cameraPosition) }
311
- ?.let { promise.resolve(it.currentState.toJson()) }
312
- ?: throw IllegalStateException(
313
- "Camera at $cameraPosition has yet not been instantiated."
314
- )
332
+ ?.takeIf { it.position == CameraPositionDeserializer.fromJson(cameraPosition) }
333
+ ?.let { promise.resolve(it.currentState.toJson()) }
334
+ ?: throw IllegalStateException(
335
+ "Camera at $cameraPosition has yet not been instantiated."
336
+ )
315
337
  } catch (e: IllegalStateException) {
316
338
  promise.reject(e)
317
339
  }
@@ -342,14 +364,16 @@ class ScanditDataCaptureCoreModule(
342
364
  camera?.let {
343
365
  if (json.contains("desiredTorchState")) {
344
366
  it.desiredTorchState = TorchStateDeserializer.fromJson(
345
- json.requireByKeyAsString("desiredTorchState")
367
+ json.requireByKeyAsString("desiredTorchState")
346
368
  )
347
369
  }
348
370
 
349
371
  if (json.contains("desiredState")) {
350
- it.switchToDesiredState(FrameSourceStateDeserializer.fromJson(
372
+ it.switchToDesiredState(
373
+ FrameSourceStateDeserializer.fromJson(
351
374
  json.requireByKeyAsString("desiredState")
352
- ))
375
+ )
376
+ )
353
377
  }
354
378
  }
355
379
  }
@@ -20,9 +20,9 @@ data class SerializableBrushDefaults(
20
20
  ) : SerializableData {
21
21
 
22
22
  constructor(brush: Brush?) : this(
23
- fillColor = brush?.fillColor?.hexString,
24
- strokeColor = brush?.strokeColor?.hexString,
25
- strokeWidth = brush?.strokeWidth
23
+ fillColor = brush?.fillColor?.hexString,
24
+ strokeColor = brush?.strokeColor?.hexString,
25
+ strokeWidth = brush?.strokeWidth
26
26
  )
27
27
 
28
28
  override fun toWritableMap(): WritableMap = writableMap {
@@ -23,9 +23,12 @@ data class SerializableCameraDefaults(
23
23
  override fun toWritableMap(): WritableMap = writableMap {
24
24
  putData(FIELD_CAMERA_SETTINGS_DEFAULTS, cameraSettingsDefaults)
25
25
  putString(FIELD_DEFAULT_POSITION, defaultPosition)
26
- putArray(FIELD_AVAILABLE_POSITIONS, writableArray {
27
- availablePositions.forEach { pushString(it.toJson()) }
28
- })
26
+ putArray(
27
+ FIELD_AVAILABLE_POSITIONS,
28
+ writableArray {
29
+ availablePositions.forEach { pushString(it.toJson()) }
30
+ }
31
+ )
29
32
  }
30
33
 
31
34
  companion object {
@@ -22,12 +22,12 @@ data class SerializableCameraSettingsDefaults(
22
22
  ) : SerializableData {
23
23
 
24
24
  constructor(settings: CameraSettings) : this(
25
- prefResolution = settings.preferredResolution.toJson(),
26
- zoomFactor = settings.zoomFactor,
27
- focusRange = "full",
28
- zoomGestureZoomFactor = settings.zoomGestureZoomFactor,
29
- focusGestureStrategy = settings.focusGestureStrategy.toJson(),
30
- shouldPreferSmoothAutoFocus = settings.shouldPreferSmoothAutoFocus
25
+ prefResolution = settings.preferredResolution.toJson(),
26
+ zoomFactor = settings.zoomFactor,
27
+ focusRange = "full",
28
+ zoomGestureZoomFactor = settings.zoomGestureZoomFactor,
29
+ focusGestureStrategy = settings.focusGestureStrategy.toJson(),
30
+ shouldPreferSmoothAutoFocus = settings.shouldPreferSmoothAutoFocus
31
31
  )
32
32
 
33
33
  override fun toWritableMap(): WritableMap = writableMap {
@@ -21,7 +21,8 @@ class SerializableLaserlineViewfinderDefaults(
21
21
 
22
22
  override fun toWritableMap(): WritableMap = writableMap {
23
23
  putString(FIELD_VIEW_FINDER_DEFAULT_STYLE, viewFinder.style.toJson())
24
- putMap(FIELD_VIEW_FINDER_STYLES,
24
+ putMap(
25
+ FIELD_VIEW_FINDER_STYLES,
25
26
  writableMap {
26
27
  putMap(
27
28
  LaserlineViewfinderStyle.ANIMATED.toJson(),
@@ -20,20 +20,23 @@ class SerializableRectangularViewfinderDefaults(
20
20
 
21
21
  override fun toWritableMap(): WritableMap = writableMap {
22
22
  putString(FIELD_VIEW_FINDER_DEFAULT_STYLE, rectangularViewfinder.style.toJson())
23
- putMap(FIELD_VIEW_FINDER_STYLES, writableMap {
24
- putMap(
25
- RectangularViewfinderStyle.LEGACY.toJson(),
26
- createViewfinderDefaults(RectangularViewfinderStyle.LEGACY)
27
- )
28
- putMap(
29
- RectangularViewfinderStyle.ROUNDED.toJson(),
30
- createViewfinderDefaults(RectangularViewfinderStyle.ROUNDED)
31
- )
32
- putMap(
33
- RectangularViewfinderStyle.SQUARE.toJson(),
34
- createViewfinderDefaults(RectangularViewfinderStyle.SQUARE)
35
- )
36
- })
23
+ putMap(
24
+ FIELD_VIEW_FINDER_STYLES,
25
+ writableMap {
26
+ putMap(
27
+ RectangularViewfinderStyle.LEGACY.toJson(),
28
+ createViewfinderDefaults(RectangularViewfinderStyle.LEGACY)
29
+ )
30
+ putMap(
31
+ RectangularViewfinderStyle.ROUNDED.toJson(),
32
+ createViewfinderDefaults(RectangularViewfinderStyle.ROUNDED)
33
+ )
34
+ putMap(
35
+ RectangularViewfinderStyle.SQUARE.toJson(),
36
+ createViewfinderDefaults(RectangularViewfinderStyle.SQUARE)
37
+ )
38
+ }
39
+ )
37
40
  }
38
41
 
39
42
  private fun createViewfinderDefaults(
@@ -43,9 +46,11 @@ class SerializableRectangularViewfinderDefaults(
43
46
  writableMap {
44
47
  putString(FIELD_VIEW_FINDER_SIZE, sizeWithUnitAndAspect.toJson())
45
48
  putString(FIELD_VIEW_FINDER_COLOR, color.hexString)
49
+ putString(FIELD_VIEW_FINDER_DISABLED_COLOR, disabledColor.hexString)
46
50
  putString(FIELD_VIEW_FINDER_STYLE, style.toJson())
47
51
  putString(FIELD_VIEW_FINDER_LINE_STYLE, lineStyle.toJson())
48
52
  putDouble(FIELD_VIEW_FINDER_DIMMING, dimming.toDouble())
53
+ putDouble(FIELD_VIEW_FINDER_DISABLED_DIMMING, disabledDimming.toDouble())
49
54
  putString(FIELD_VIEW_FINDER_ANIMATION, animation?.toJson())
50
55
  }
51
56
  }
@@ -56,9 +61,11 @@ class SerializableRectangularViewfinderDefaults(
56
61
  private const val FIELD_VIEW_FINDER_STYLES = "styles"
57
62
  private const val FIELD_VIEW_FINDER_SIZE = "size"
58
63
  private const val FIELD_VIEW_FINDER_COLOR = "color"
64
+ private const val FIELD_VIEW_FINDER_DISABLED_COLOR = "disabledColor"
59
65
  private const val FIELD_VIEW_FINDER_STYLE = "style"
60
66
  private const val FIELD_VIEW_FINDER_LINE_STYLE = "lineStyle"
61
67
  private const val FIELD_VIEW_FINDER_DIMMING = "dimming"
68
+ private const val FIELD_VIEW_FINDER_DISABLED_DIMMING = "disabledDimming"
62
69
  private const val FIELD_VIEW_FINDER_ANIMATION = "animation"
63
70
  }
64
71
  }
@@ -48,31 +48,31 @@ class Deserializers private constructor(
48
48
  fun create(
49
49
  context: Context,
50
50
  frameSourceDeserializerListener:
51
- FrameSourceDeserializerListener
51
+ FrameSourceDeserializerListener
52
52
  ): Deserializers {
53
53
  return Deserializers(
54
- context,
55
- modeDeserializers,
56
- componentDeserializers,
57
- frameSourceDeserializerListener
54
+ context,
55
+ modeDeserializers,
56
+ componentDeserializers,
57
+ frameSourceDeserializerListener
58
58
  )
59
59
  }
60
60
  }
61
61
 
62
62
  private val frameSourceDeserializer: FrameSourceDeserializer =
63
- FrameSourceDeserializer(modeDeserializers).apply {
64
- listener = frameSourceDeserializerListener
65
- }
63
+ FrameSourceDeserializer(modeDeserializers).apply {
64
+ listener = frameSourceDeserializerListener
65
+ }
66
66
  private val dataCaptureViewDeserializer: DataCaptureViewDeserializer =
67
- DataCaptureViewDeserializer(context, modeDeserializers)
67
+ DataCaptureViewDeserializer(context, modeDeserializers)
68
68
 
69
69
  val dataCaptureContextDeserializer: DataCaptureContextDeserializer =
70
- DataCaptureContextDeserializer(
71
- frameSourceDeserializer,
72
- dataCaptureViewDeserializer,
73
- modeDeserializers,
74
- componentDeserializers
75
- ).apply {
76
- avoidThreadDependencies = true
77
- }
70
+ DataCaptureContextDeserializer(
71
+ frameSourceDeserializer,
72
+ dataCaptureViewDeserializer,
73
+ modeDeserializers,
74
+ componentDeserializers
75
+ ).apply {
76
+ avoidThreadDependencies = true
77
+ }
78
78
  }
@@ -32,14 +32,14 @@ object TreeLifecycleObserver {
32
32
  }
33
33
 
34
34
  interface Callbacks {
35
- fun onTreeCreated(root: DataCaptureContext) = Unit
35
+ fun onTreeCreated(root: DataCaptureContext) { }
36
36
 
37
- fun onTreeDestroyed() = Unit
37
+ fun onTreeDestroyed() { }
38
38
 
39
- fun onBarcodeTrackingRemoved() = Unit
39
+ fun onBarcodeTrackingRemoved() { }
40
40
 
41
- fun onBarcodeTrackingAdvancedOverlayRemoved() = Unit
41
+ fun onBarcodeTrackingAdvancedOverlayRemoved() { }
42
42
 
43
- fun onParsersRemoved() = Unit
43
+ fun onParsersRemoved() { }
44
44
  }
45
45
  }
@@ -20,9 +20,9 @@ class RCTDataCaptureContextListener(
20
20
 
21
21
  companion object {
22
22
  private const val ON_OBSERVATION_STARTED_EVENT_NAME =
23
- "dataCaptureContextListener-didStartObservingContext"
23
+ "dataCaptureContextListener-didStartObservingContext"
24
24
  private const val ON_STATUS_CHANGED_EVENT_NAME =
25
- "dataCaptureContextListener-didChangeStatus"
25
+ "dataCaptureContextListener-didChangeStatus"
26
26
 
27
27
  private const val FIELD_STATUS = "status"
28
28
  }
@@ -32,12 +32,18 @@ class RCTDataCaptureViewListener(
32
32
  if (!hasNativeListeners.get()) return
33
33
 
34
34
  val params = writableMap {
35
- putMap(FIELD_SIZE, writableMap {
36
- putInt(FIELD_WIDTH, width)
37
- putInt(FIELD_HEIGHT, height)
38
- })
39
- putString(FIELD_ORIENTATION, DeviceOrientationMapper()
40
- .mapRotationToOrientation(screenRotation).toJson())
35
+ putMap(
36
+ FIELD_SIZE,
37
+ writableMap {
38
+ putInt(FIELD_WIDTH, width)
39
+ putInt(FIELD_HEIGHT, height)
40
+ }
41
+ )
42
+ putString(
43
+ FIELD_ORIENTATION,
44
+ DeviceOrientationMapper()
45
+ .mapRotationToOrientation(screenRotation).toJson()
46
+ )
41
47
  }
42
48
  eventEmitter.emit(ON_SIZE_CHANGED_EVENT_NAME, params)
43
49
  }
@@ -17,8 +17,9 @@ import com.facebook.react.uimanager.ViewGroupManager
17
17
  import com.scandit.datacapture.core.ui.DataCaptureView
18
18
  import com.scandit.datacapture.reactnative.core.handler.DataCaptureViewHandler
19
19
 
20
- class DataCaptureViewManager : ViewGroupManager<FrameLayout>(),
21
- DataCaptureViewHandler.ViewListener {
20
+ class DataCaptureViewManager :
21
+ ViewGroupManager<FrameLayout>(),
22
+ DataCaptureViewHandler.ViewListener {
22
23
 
23
24
  @get:VisibleForTesting
24
25
  var container: FrameLayout? = null
@@ -76,8 +77,10 @@ class DataCaptureViewManager : ViewGroupManager<FrameLayout>(),
76
77
  container?.let { container ->
77
78
  for (i in 0 until container.childCount) {
78
79
  val child = container.getChildAt(i)
79
- child.measure(makeMeasureSpec(container.measuredWidth, View.MeasureSpec.EXACTLY),
80
- makeMeasureSpec(container.measuredHeight, View.MeasureSpec.EXACTLY))
80
+ child.measure(
81
+ makeMeasureSpec(container.measuredWidth, View.MeasureSpec.EXACTLY),
82
+ makeMeasureSpec(container.measuredHeight, View.MeasureSpec.EXACTLY)
83
+ )
81
84
  child.layout(0, 0, child.measuredWidth, child.measuredHeight)
82
85
  }
83
86
  }
@@ -18,19 +18,19 @@ val Int.hexString: String
18
18
  get() {
19
19
  val hex = String.format(Locale.getDefault(), "%08X", this)
20
20
  return "#" + // ts is expecting the color in format #RRGGBBAA, we need to move the alpha.
21
- hex.substring(2) + // RRGGBB
22
- hex.substring(0, 2) // AA
21
+ hex.substring(2) + // RRGGBB
22
+ hex.substring(0, 2) // AA
23
23
  }
24
24
 
25
25
  inline fun writableMap(builder: WritableMap.() -> Unit): WritableMap =
26
- Arguments.createMap().apply(builder)
26
+ Arguments.createMap().apply(builder)
27
27
 
28
28
  inline fun writableArray(builder: WritableArray.() -> Unit): WritableArray =
29
- Arguments.createArray().apply(builder)
29
+ Arguments.createArray().apply(builder)
30
30
 
31
31
  fun WritableMap.putData(key: String, data: SerializableData) {
32
32
  putMap(key, data.toWritableMap())
33
33
  }
34
34
 
35
35
  inline fun <reified T : JavaScriptModule> ReactApplicationContext.getJSModule(): T =
36
- getJSModule(T::class.java)
36
+ getJSModule(T::class.java)
@@ -10,7 +10,6 @@ import androidx.annotation.VisibleForTesting
10
10
  import com.facebook.react.bridge.Promise
11
11
  import com.facebook.react.bridge.WritableMap
12
12
  import com.scandit.datacapture.reactnative.core.utils.TestPromise.Status.*
13
- import java.lang.AssertionError
14
13
 
15
14
  @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
16
15
  fun promise(): TestPromise = TestPromise()
@@ -96,22 +95,8 @@ class TestPromise : Promise {
96
95
 
97
96
  override fun toString(): String {
98
97
  return "TestPromise(value=$value, code=$code, message=$message, throwable=$throwable, " +
99
- "userInfo=$userInfo, status=$status)"
98
+ "userInfo=$userInfo, status=$status)"
100
99
  }
101
100
 
102
101
  enum class Status { PENDING, RESOLVED, REJECTED }
103
102
  }
104
-
105
- inline fun waitTill(conditionDescription: String, forMs: Long = 5000L, condition: () -> Boolean) {
106
- val iterCount = forMs / 50
107
-
108
- for (i in 0..iterCount) {
109
- if (condition()) {
110
- return
111
- }
112
-
113
- Thread.sleep(50)
114
- }
115
-
116
- throw AssertionError("Still false after ${forMs}ms: $conditionDescription")
117
- }
@@ -88,8 +88,10 @@ extension ScanditDataCaptureCore {
88
88
  "style": viewfinder.style.jsonString,
89
89
  "size": viewfinder.sizeWithUnitAndAspect.jsonString,
90
90
  "color": viewfinder.color.sdcHexString,
91
+ "disabledColor": viewfinder.disabledColor.sdcHexString,
91
92
  "lineStyle": viewfinder.lineStyle.jsonString,
92
93
  "dimming": viewfinder.dimming,
94
+ "disabledDimming": viewfinder.disabledDimming,
93
95
  "animation": viewfinder.animation?.jsonString as Any
94
96
  ]
95
97
  return defaults
@@ -50,6 +50,10 @@ RCT_EXTERN_METHOD(isTorchAvailable
50
50
  : (RCTPromiseResolveBlock)resolve reject
51
51
  : (RCTPromiseRejectBlock)reject)
52
52
 
53
+ RCT_EXTERN_METHOD(getLastFrame
54
+ : (RCTPromiseResolveBlock)resolve reject
55
+ : (RCTPromiseRejectBlock)reject)
56
+
53
57
  RCT_EXTERN_METHOD(registerListenerForCameraEvents)
54
58
 
55
59
  RCT_EXTERN_METHOD(unregisterListenerForCameraEvents)
@@ -17,6 +17,7 @@ public let SDCSharedMethodQeueue = DispatchQueue(label: "com.scandit.reactnative
17
17
  enum ScanditDataCaptureCoreError: Int, CustomNSError {
18
18
  case deserializationError = 1
19
19
  case nilDataCaptureView
20
+ case nilFrame
20
21
 
21
22
  var domain: String { return "ScanditDataCaptureCoreErrorDomain" }
22
23
 
@@ -30,6 +31,8 @@ enum ScanditDataCaptureCoreError: Int, CustomNSError {
30
31
  return "Unable to deserialize a valid object."
31
32
  case .nilDataCaptureView:
32
33
  return "DataCaptureView is null."
34
+ case .nilFrame:
35
+ return "Frame is null, it might've been reused already."
33
36
  }
34
37
  }
35
38
 
@@ -63,6 +66,8 @@ public class ScanditDataCaptureCore: RCTEventEmitter {
63
66
  .forEach { $0.didUpdate(dataCaptureView: dataCaptureView) }
64
67
  }
65
68
  }
69
+
70
+ public static var lastFrame: FrameData?
66
71
 
67
72
  lazy internal var contextDeserializer: DataCaptureContextDeserializer = {
68
73
  return DataCaptureContextDeserializer(frameSourceDeserializer: frameSourceDeserializer,
@@ -249,6 +254,17 @@ public class ScanditDataCaptureCore: RCTEventEmitter {
249
254
  let camera = Camera(position: position)
250
255
  resolve(camera?.isTorchAvailable ?? false)
251
256
  }
257
+
258
+ @objc(getLastFrame:reject:)
259
+ func getLastFrame(resolve: @escaping RCTPromiseResolveBlock,
260
+ reject: @escaping RCTPromiseRejectBlock) {
261
+ guard let lastFrame = ScanditDataCaptureCore.lastFrame else {
262
+ let error = ScanditDataCaptureCoreError.nilFrame
263
+ reject(String(error.code), error.message, error)
264
+ return
265
+ }
266
+ resolve(lastFrame.jsonString)
267
+ }
252
268
 
253
269
  public func addRNTDataCaptureViewListener(_ listener: RNTDataCaptureViewListener) {
254
270
  pthread_mutex_lock(&dataCaptureViewListenersLock)
@@ -46,3 +46,15 @@ export declare class CameraSettings extends DefaultSerializeable {
46
46
  setProperty(name: string, value: any): void;
47
47
  getProperty(name: string): any;
48
48
  }
49
+ export interface FrameData {
50
+ readonly imageBuffers: ImageBuffer[];
51
+ readonly orientation: number;
52
+ }
53
+ export declare class ImageBuffer {
54
+ private _width;
55
+ private _height;
56
+ private _data;
57
+ get width(): number;
58
+ get height(): number;
59
+ get data(): string;
60
+ }