scandit-react-native-datacapture-core 7.0.0-beta.2 → 7.0.1

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.
@@ -68,7 +68,7 @@ if (file( "${rootProject.projectDir}/build-test.gradle").exists()) {
68
68
  }
69
69
 
70
70
  dependencies {
71
- def sdk_version = "7.0.0-beta.2"
71
+ def sdk_version = "7.0.1"
72
72
 
73
73
  println("Version of the native sdk used in this build: ${safeExtGet('global_sdk_version', sdk_version)}")
74
74
  if (findProject(':scandit-datacapture-frameworks-core') != null) {
@@ -12,34 +12,25 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule
12
12
  import com.facebook.react.bridge.ReactMethod
13
13
  import com.scandit.datacapture.core.capture.DataCaptureVersion
14
14
  import com.scandit.datacapture.frameworks.core.CoreModule
15
- import com.scandit.datacapture.frameworks.core.deserialization.DefaultDeserializationLifecycleObserver
16
- import com.scandit.datacapture.frameworks.core.deserialization.DeserializationLifecycleObserver
15
+ import com.scandit.datacapture.frameworks.core.FrameworkModule
16
+ import com.scandit.datacapture.frameworks.core.errors.ModuleNotStartedError
17
+ import com.scandit.datacapture.frameworks.core.locator.ServiceLocator
17
18
  import com.scandit.datacapture.frameworks.core.utils.DefaultMainThread
18
19
  import com.scandit.datacapture.frameworks.core.utils.MainThread
19
20
  import com.scandit.datacapture.reactnative.core.utils.ReactNativeResult
20
21
 
21
22
  class ScanditDataCaptureCoreModule(
22
23
  reactContext: ReactApplicationContext,
23
- private val coreModule: CoreModule,
24
+ private val serviceLocator: ServiceLocator<FrameworkModule>,
24
25
  private val mainThread: MainThread = DefaultMainThread.getInstance(),
25
- ) : ReactContextBaseJavaModule(reactContext), DeserializationLifecycleObserver.Observer {
26
+ ) : ReactContextBaseJavaModule(reactContext) {
26
27
 
27
28
  companion object {
28
29
  private const val VERSION_KEY = "Version"
29
30
  private const val DEFAULTS_KEY = "Defaults"
30
31
  }
31
-
32
- private val deserializationLifecycleObserver: DeserializationLifecycleObserver =
33
- DefaultDeserializationLifecycleObserver.getInstance()
34
-
35
- init {
36
- coreModule.onCreate(reactContext)
37
- deserializationLifecycleObserver.attach(this)
38
- }
39
-
40
32
  override fun invalidate() {
41
33
  coreModule.onDestroy()
42
- deserializationLifecycleObserver.detach(this)
43
34
  super.invalidate()
44
35
  }
45
36
 
@@ -161,4 +152,10 @@ class ScanditDataCaptureCoreModule(
161
152
  fun getOpenSourceSoftwareLicenseInfo(promise: Promise) {
162
153
  coreModule.getOpenSourceSoftwareLicenseInfo(ReactNativeResult(promise))
163
154
  }
155
+
156
+ private val coreModule: CoreModule
157
+ get() {
158
+ return serviceLocator.resolve(CoreModule::class.java.name) as? CoreModule?
159
+ ?: throw ModuleNotStartedError(ScanditDataCaptureCoreModule::class.java.simpleName)
160
+ }
164
161
  }
@@ -14,46 +14,51 @@ import com.scandit.datacapture.frameworks.core.events.Emitter
14
14
  import com.scandit.datacapture.frameworks.core.listeners.FrameworksDataCaptureContextListener
15
15
  import com.scandit.datacapture.frameworks.core.listeners.FrameworksDataCaptureViewListener
16
16
  import com.scandit.datacapture.frameworks.core.listeners.FrameworksFrameSourceListener
17
+ import com.scandit.datacapture.frameworks.core.locator.DefaultServiceLocator
17
18
  import com.scandit.datacapture.reactnative.core.ui.DataCaptureViewManager
18
19
  import com.scandit.datacapture.reactnative.core.utils.ReactNativeEventEmitter
20
+ import java.util.concurrent.locks.ReentrantLock
19
21
 
20
22
  class ScanditDataCaptureCorePackage : ReactPackage {
23
+ private val serviceLocator = DefaultServiceLocator.getInstance()
24
+
21
25
  override fun createNativeModules(
22
26
  reactContext: ReactApplicationContext
23
- ): MutableList<NativeModule> =
24
- mutableListOf(
27
+ ): MutableList<NativeModule> {
28
+ setupSharedModule(reactContext)
29
+ return mutableListOf(
25
30
  ScanditDataCaptureCoreModule(
26
31
  reactContext,
27
- getCoreModule(
28
- reactContext
29
- ),
32
+ serviceLocator,
30
33
  )
31
34
  )
35
+ }
32
36
 
33
37
  override fun createViewManagers(
34
38
  reactContext: ReactApplicationContext
35
- ): MutableList<ViewManager<*, *>> =
36
- mutableListOf(DataCaptureViewManager(getCoreModule(reactContext)))
39
+ ): MutableList<ViewManager<*, *>> = mutableListOf(DataCaptureViewManager(serviceLocator))
37
40
 
38
- private var coreModule: CoreModule? = null
41
+ private fun setupSharedModule(reactContext: ReactApplicationContext) {
42
+ lock.lock()
43
+ try {
44
+ // In React-Native if this function is called again we have to cleanup the existing
45
+ // instances and re-create them again.
46
+ serviceLocator.remove(CoreModule::class.java.name)
39
47
 
40
- private fun getCoreModule(reactContext: ReactApplicationContext): CoreModule {
41
- val existingInstance = this.coreModule
42
- if (existingInstance != null) {
43
- return existingInstance.also {
44
- it.onCreate(reactContext)
45
- }
48
+ val eventEmitter: Emitter = ReactNativeEventEmitter(reactContext)
49
+ val coreModule = CoreModule.create(
50
+ FrameworksFrameSourceListener(eventEmitter),
51
+ FrameworksDataCaptureContextListener(eventEmitter),
52
+ FrameworksDataCaptureViewListener(eventEmitter)
53
+ )
54
+ coreModule.onCreate(reactContext)
55
+ serviceLocator.register(coreModule)
56
+ } finally {
57
+ lock.unlock()
46
58
  }
59
+ }
47
60
 
48
- val eventEmitter: Emitter = ReactNativeEventEmitter(reactContext)
49
- val instance = CoreModule(
50
- FrameworksFrameSourceListener(
51
- eventEmitter
52
- ),
53
- FrameworksDataCaptureContextListener(eventEmitter),
54
- FrameworksDataCaptureViewListener(eventEmitter)
55
- )
56
- this.coreModule = instance
57
- return instance
61
+ companion object {
62
+ private val lock: ReentrantLock = ReentrantLock()
58
63
  }
59
64
  }
@@ -9,17 +9,19 @@ package com.scandit.datacapture.reactnative.core.ui
9
9
  import android.view.ViewGroup
10
10
  import android.view.ViewGroup.LayoutParams.MATCH_PARENT
11
11
  import android.widget.FrameLayout
12
+ import com.facebook.react.bridge.ReadableArray
12
13
  import com.facebook.react.uimanager.ThemedReactContext
13
14
  import com.scandit.datacapture.core.ui.DataCaptureView
14
15
  import com.scandit.datacapture.frameworks.core.CoreModule
16
+ import com.scandit.datacapture.frameworks.core.FrameworkModule
17
+ import com.scandit.datacapture.frameworks.core.errors.ModuleNotStartedError
15
18
  import com.scandit.datacapture.frameworks.core.handlers.DataCaptureViewHandler
16
19
  import com.scandit.datacapture.frameworks.core.handlers.DefaultDataCaptureViewHandler
17
- import com.scandit.datacapture.frameworks.core.utils.DefaultMainThread
18
- import com.scandit.datacapture.frameworks.core.utils.MainThread
20
+ import com.scandit.datacapture.frameworks.core.locator.ServiceLocator
21
+ import com.scandit.datacapture.frameworks.core.result.NoopFrameworksResult
19
22
 
20
23
  class DataCaptureViewManager(
21
- private val codeModule: CoreModule,
22
- private val mainThread: MainThread = DefaultMainThread.getInstance(),
24
+ private val serviceLocator: ServiceLocator<FrameworkModule>,
23
25
  private val dataCaptureViewHandler: DataCaptureViewHandler =
24
26
  DefaultDataCaptureViewHandler.getInstance()
25
27
  ) : ScanditViewGroupManager<FrameLayout>() {
@@ -29,20 +31,12 @@ class DataCaptureViewManager(
29
31
  override fun createNewInstance(reactContext: ThemedReactContext): FrameLayout =
30
32
  FrameLayout(reactContext)
31
33
 
32
- override fun createViewInstance(reactContext: ThemedReactContext): FrameLayout {
33
- val container = super.createViewInstance(reactContext)
34
- dataCaptureViewHandler.topmostDataCaptureView?.let { view ->
35
- addDataCaptureViewToContainer(view, container)
36
- }
37
- return container
38
- }
39
-
40
34
  override fun onDropViewInstance(view: FrameLayout) {
41
35
  // remove current DCView from core cache
42
36
  for (i in 0 until view.childCount) {
43
37
  val child = view.getChildAt(i)
44
38
  if (child is DataCaptureView) { // it should always be a DCView but you never know
45
- codeModule.dataCaptureViewDisposed(child)
39
+ coreModule.dataCaptureViewDisposed(child)
46
40
  }
47
41
  }
48
42
 
@@ -55,15 +49,31 @@ class DataCaptureViewManager(
55
49
  }
56
50
  }
57
51
 
52
+ override fun getCommandsMap(): MutableMap<String, Int> = mutableMapOf(
53
+ CREATE_FRAGMENT_COMMAND to CREATE_FRAGMENT_COMMAND_INDEX
54
+ )
55
+
56
+ override fun receiveCommand(root: FrameLayout, commandId: String?, args: ReadableArray?) {
57
+ if (commandId == CREATE_FRAGMENT_COMMAND) {
58
+ val viewJson = args?.getString(0) ?: return
59
+
60
+ coreModule.createDataCaptureView(viewJson, NoopFrameworksResult())?.let {
61
+ currentContainer?.let { container ->
62
+ addDataCaptureViewToContainer(it, container)
63
+ }
64
+ }
65
+ }
66
+ }
67
+
58
68
  private fun addDataCaptureViewToContainer(
59
69
  dataCaptureView: DataCaptureView,
60
70
  container: FrameLayout
61
71
  ) {
62
- mainThread.runOnMainThread {
72
+ container.post {
63
73
  if (container.childCount > 0 && container.getChildAt(0) === dataCaptureView) {
64
74
  // Same instance already attached. No need to detach and attach it again because
65
75
  // it will trigger some overlay cleanup that we don't want.
66
- return@runOnMainThread
76
+ return@post
67
77
  }
68
78
 
69
79
  /*
@@ -80,4 +90,15 @@ class DataCaptureViewManager(
80
90
  container.addView(dataCaptureView, MATCH_PARENT, MATCH_PARENT)
81
91
  }
82
92
  }
93
+
94
+ private val coreModule: CoreModule
95
+ get() {
96
+ return serviceLocator.resolve(CoreModule::class.java.name) as? CoreModule?
97
+ ?: throw ModuleNotStartedError(DataCaptureViewManager::class.java.simpleName)
98
+ }
99
+
100
+ companion object {
101
+ private const val CREATE_FRAGMENT_COMMAND_INDEX = 1
102
+ private const val CREATE_FRAGMENT_COMMAND = "createDataCaptureView"
103
+ }
83
104
  }
@@ -12,17 +12,13 @@ import android.view.ViewGroup
12
12
  import com.facebook.react.uimanager.ThemedReactContext
13
13
  import com.facebook.react.uimanager.ViewGroupManager
14
14
 
15
- abstract class ScanditViewGroupManager<T> : ViewGroupManager<T>() where T : ViewGroup {
15
+ abstract class ScanditViewGroupManager<T> :
16
+ ViewGroupManager<T>() where T : ViewGroup {
16
17
  private val containers = mutableListOf<T>()
17
18
 
18
- protected val fragmentsCache: MutableMap<T, FragmentBase> = mutableMapOf()
19
-
20
19
  val currentContainer: T?
21
20
  get() = if (containers.size > 0) containers[containers.size - 1] else null
22
21
 
23
- // Action to be executed after the container is created via the createViewInstance function
24
- var postContainerCreationAction: (() -> Unit)? = null
25
-
26
22
  abstract fun createNewInstance(reactContext: ThemedReactContext): T
27
23
 
28
24
  override fun invalidate() {
@@ -38,8 +34,6 @@ abstract class ScanditViewGroupManager<T> : ViewGroupManager<T>() where T : View
38
34
  if (containers.size == 1) {
39
35
  scheduleMeasureAndLayout()
40
36
  }
41
- postContainerCreationAction?.invoke()
42
- postContainerCreationAction = null
43
37
  return container
44
38
  }
45
39
 
package/dist/core.js CHANGED
@@ -2655,13 +2655,9 @@ function parseDefaults(jsonDefaults) {
2655
2655
  frameColor: Color.fromJSON(jsonDefaults.AimerViewfinder.frameColor),
2656
2656
  dotColor: Color.fromJSON(jsonDefaults.AimerViewfinder.dotColor),
2657
2657
  },
2658
- Brush: {
2659
- fillColor: Color
2660
- .fromJSON(jsonDefaults.Brush.fillColor),
2661
- strokeColor: Color
2662
- .fromJSON(jsonDefaults.Brush.strokeColor),
2663
- strokeWidth: jsonDefaults.Brush.strokeWidth,
2664
- },
2658
+ Brush: new Brush(Color
2659
+ .fromJSON(jsonDefaults.Brush.fillColor), Color
2660
+ .fromJSON(jsonDefaults.Brush.strokeColor), jsonDefaults.Brush.strokeWidth),
2665
2661
  deviceID: jsonDefaults.deviceID,
2666
2662
  };
2667
2663
  // Inject defaults to avoid a circular dependency between these classes and the defaults