scandit-react-native-datacapture-core 7.1.0 → 7.2.0-beta.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.
package/THIRD_PARTY.txt CHANGED
@@ -236,55 +236,6 @@ includes components licensed under the following licenses:
236
236
  SOFTWARE.
237
237
 
238
238
 
239
- ================================================================================
240
-
241
-
242
- Copyright 1985, 1987, 1988, 1990, 1991, 1993-1996, 1998 The Open Group
243
-
244
- Permission to use, copy, modify, distribute, and sell this software and its
245
- documentation for any purpose is hereby granted without fee, provided that
246
- the above copyright notice appear in all copies and that both that
247
- copyright notice and this permission notice appear in supporting
248
- documentation.
249
-
250
- The above copyright notice and this permission notice shall be included in
251
- all copies or substantial portions of the Software.
252
-
253
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
254
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
255
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
256
- OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
257
- AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
258
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
259
-
260
- Except as contained in this notice, the name of The Open Group shall not be
261
- used in advertising or otherwise to promote the sale, use or other dealings
262
- in this Software without prior written authorization from The Open Group.
263
-
264
- The X Window System is a Trademark of The Open Group.
265
-
266
-
267
- Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
268
-
269
- All Rights Reserved
270
-
271
- Permission to use, copy, modify, and distribute this software and its
272
- documentation for any purpose and without fee is hereby granted,
273
- provided that the above copyright notice appear in all copies and that
274
- both that copyright notice and this permission notice appear in
275
- supporting documentation, and that the name of Digital not be
276
- used in advertising or publicity pertaining to distribution of the
277
- software without specific, written prior permission.
278
-
279
- DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
280
- ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
281
- DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
282
- ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
283
- WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
284
- ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
285
- SOFTWARE.
286
-
287
-
288
239
  ================================================================================
289
240
 
290
241
 
@@ -68,7 +68,7 @@ if (file( "${rootProject.projectDir}/build-test.gradle").exists()) {
68
68
  }
69
69
 
70
70
  dependencies {
71
- def sdk_version = "7.1.0"
71
+ def sdk_version = "7.2.0-beta.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) {
@@ -10,6 +10,7 @@ import com.facebook.react.bridge.Promise
10
10
  import com.facebook.react.bridge.ReactApplicationContext
11
11
  import com.facebook.react.bridge.ReactContextBaseJavaModule
12
12
  import com.facebook.react.bridge.ReactMethod
13
+ import com.facebook.react.uimanager.ViewGroupManager
13
14
  import com.scandit.datacapture.core.capture.DataCaptureVersion
14
15
  import com.scandit.datacapture.frameworks.core.CoreModule
15
16
  import com.scandit.datacapture.frameworks.core.FrameworkModule
@@ -17,18 +18,26 @@ import com.scandit.datacapture.frameworks.core.errors.ModuleNotStartedError
17
18
  import com.scandit.datacapture.frameworks.core.locator.ServiceLocator
18
19
  import com.scandit.datacapture.frameworks.core.utils.DefaultMainThread
19
20
  import com.scandit.datacapture.frameworks.core.utils.MainThread
21
+ import com.scandit.datacapture.reactnative.core.ui.DataCaptureViewManager
20
22
  import com.scandit.datacapture.reactnative.core.utils.ReactNativeResult
21
23
 
22
24
  class ScanditDataCaptureCoreModule(
23
25
  reactContext: ReactApplicationContext,
24
26
  private val serviceLocator: ServiceLocator<FrameworkModule>,
27
+ private val viewManagers: Map<String, ViewGroupManager<*>>,
25
28
  private val mainThread: MainThread = DefaultMainThread.getInstance(),
26
29
  ) : ReactContextBaseJavaModule(reactContext) {
27
30
 
28
31
  companion object {
29
32
  private const val VERSION_KEY = "Version"
30
33
  private const val DEFAULTS_KEY = "Defaults"
34
+
35
+ private val VIEW_MANAGER_NULL_ERROR = Error(
36
+ "Unable to add the DataCaptureView on Android. " +
37
+ "The DataCaptureViewManager instance is null."
38
+ )
31
39
  }
40
+
32
41
  override fun invalidate() {
33
42
  coreModule.onDestroy()
34
43
  super.invalidate()
@@ -140,7 +149,14 @@ class ScanditDataCaptureCoreModule(
140
149
 
141
150
  @ReactMethod
142
151
  fun createDataCaptureView(viewJson: String, promise: Promise) {
143
- coreModule.createDataCaptureView(viewJson, ReactNativeResult(promise))
152
+ val viewManager = viewManagers[DataCaptureViewManager::class.java.name] as?
153
+ DataCaptureViewManager
154
+ if (viewManager == null) {
155
+ promise.reject(VIEW_MANAGER_NULL_ERROR)
156
+ return
157
+ }
158
+
159
+ viewManager.createDataCaptureView(viewJson, promise)
144
160
  }
145
161
 
146
162
  @ReactMethod
@@ -6,37 +6,75 @@
6
6
  package com.scandit.datacapture.reactnative.core
7
7
 
8
8
  import com.facebook.react.ReactPackage
9
+ import com.facebook.react.bridge.LifecycleEventListener
9
10
  import com.facebook.react.bridge.NativeModule
10
11
  import com.facebook.react.bridge.ReactApplicationContext
12
+ import com.facebook.react.uimanager.ViewGroupManager
11
13
  import com.facebook.react.uimanager.ViewManager
12
14
  import com.scandit.datacapture.frameworks.core.CoreModule
13
15
  import com.scandit.datacapture.frameworks.core.events.Emitter
16
+ import com.scandit.datacapture.frameworks.core.lifecycle.ActivityLifecycleDispatcher
17
+ import com.scandit.datacapture.frameworks.core.lifecycle.DefaultActivityLifecycle
14
18
  import com.scandit.datacapture.frameworks.core.listeners.FrameworksDataCaptureContextListener
15
19
  import com.scandit.datacapture.frameworks.core.listeners.FrameworksDataCaptureViewListener
16
20
  import com.scandit.datacapture.frameworks.core.listeners.FrameworksFrameSourceListener
17
21
  import com.scandit.datacapture.frameworks.core.locator.DefaultServiceLocator
18
22
  import com.scandit.datacapture.reactnative.core.ui.DataCaptureViewManager
19
23
  import com.scandit.datacapture.reactnative.core.utils.ReactNativeEventEmitter
24
+ import java.util.concurrent.ConcurrentHashMap
20
25
  import java.util.concurrent.locks.ReentrantLock
21
26
 
22
27
  class ScanditDataCaptureCorePackage : ReactPackage {
23
28
  private val serviceLocator = DefaultServiceLocator.getInstance()
24
29
 
30
+ private val lifecycleDispatcher: ActivityLifecycleDispatcher =
31
+ DefaultActivityLifecycle.getInstance()
32
+
33
+ private val viewManagers: MutableMap<String, ViewGroupManager<*>> = ConcurrentHashMap()
34
+
35
+ private val lifecycleListener = object : LifecycleEventListener {
36
+ override fun onHostResume() {
37
+ lifecycleDispatcher.dispatchOnResume()
38
+ }
39
+
40
+ override fun onHostPause() {
41
+ lifecycleDispatcher.dispatchOnPause()
42
+ }
43
+
44
+ override fun onHostDestroy() {
45
+ lifecycleDispatcher.dispatchOnDestroy()
46
+ }
47
+ }
48
+
25
49
  override fun createNativeModules(
26
50
  reactContext: ReactApplicationContext
27
51
  ): MutableList<NativeModule> {
52
+ // Register to receive lifecycle events
53
+ reactContext.addLifecycleEventListener(lifecycleListener)
54
+
28
55
  setupSharedModule(reactContext)
29
56
  return mutableListOf(
30
57
  ScanditDataCaptureCoreModule(
31
58
  reactContext,
32
59
  serviceLocator,
60
+ viewManagers,
33
61
  )
34
62
  )
35
63
  }
36
64
 
37
65
  override fun createViewManagers(
38
66
  reactContext: ReactApplicationContext
39
- ): MutableList<ViewManager<*, *>> = mutableListOf(DataCaptureViewManager(serviceLocator))
67
+ ): MutableList<ViewManager<*, *>> {
68
+ // Clear existing instances of previously cached viewMangers
69
+ viewManagers.clear()
70
+
71
+ val dcViewManager = DataCaptureViewManager(serviceLocator)
72
+ // Here we register the ViewManagers and allow the different module to access them by
73
+ // using the name.
74
+ viewManagers[DataCaptureViewManager::class.java.name] = dcViewManager
75
+
76
+ return mutableListOf(dcViewManager)
77
+ }
40
78
 
41
79
  private fun setupSharedModule(reactContext: ReactApplicationContext) {
42
80
  lock.lock()
@@ -9,28 +9,44 @@ 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
+ import com.facebook.react.bridge.Promise
13
13
  import com.facebook.react.uimanager.ThemedReactContext
14
+ import com.scandit.datacapture.core.json.JsonValue
14
15
  import com.scandit.datacapture.core.ui.DataCaptureView
15
16
  import com.scandit.datacapture.frameworks.core.CoreModule
16
17
  import com.scandit.datacapture.frameworks.core.FrameworkModule
17
18
  import com.scandit.datacapture.frameworks.core.errors.ModuleNotStartedError
18
- import com.scandit.datacapture.frameworks.core.handlers.DataCaptureViewHandler
19
- import com.scandit.datacapture.frameworks.core.handlers.DefaultDataCaptureViewHandler
20
19
  import com.scandit.datacapture.frameworks.core.locator.ServiceLocator
21
- import com.scandit.datacapture.frameworks.core.result.NoopFrameworksResult
20
+ import com.scandit.datacapture.reactnative.core.utils.ReactNativeResult
21
+
22
+ private class CreateRequest(val viewJson: String, val promise: Promise)
22
23
 
23
24
  class DataCaptureViewManager(
24
25
  private val serviceLocator: ServiceLocator<FrameworkModule>,
25
- private val dataCaptureViewHandler: DataCaptureViewHandler =
26
- DefaultDataCaptureViewHandler.getInstance()
27
26
  ) : ScanditViewGroupManager<FrameLayout>() {
28
-
29
27
  override fun getName(): String = "RNTDataCaptureView"
30
28
 
29
+ private val cachedCreationRequests = mutableMapOf<Int, CreateRequest>()
30
+
31
31
  override fun createNewInstance(reactContext: ThemedReactContext): FrameLayout =
32
32
  FrameLayout(reactContext)
33
33
 
34
+ override fun onAfterUpdateTransaction(view: FrameLayout) {
35
+ super.onAfterUpdateTransaction(view)
36
+ // This is the point where the ReactNative Id on JS side (findNodeHandle) matches
37
+ // the id of the container created on native side. If createDataCaptureView was called
38
+ // before the creation of the instance of the native container, we add an item to
39
+ // cachedCreationRequests so that, after the creation the view is added to the just
40
+ // created container.
41
+ val item = cachedCreationRequests.remove(view.id)
42
+
43
+ if (item != null) {
44
+ coreModule.createDataCaptureView(item.viewJson, ReactNativeResult(item.promise))?.let {
45
+ addDataCaptureViewToContainer(it, view)
46
+ }
47
+ }
48
+ }
49
+
34
50
  override fun onDropViewInstance(view: FrameLayout) {
35
51
  // remove current DCView from core cache
36
52
  for (i in 0 until view.childCount) {
@@ -41,27 +57,24 @@ class DataCaptureViewManager(
41
57
  }
42
58
 
43
59
  super.onDropViewInstance(view)
60
+ }
44
61
 
45
- currentContainer?.let { container ->
46
- dataCaptureViewHandler.topmostDataCaptureView?.let { view ->
47
- addDataCaptureViewToContainer(view, container)
48
- }
62
+ fun createDataCaptureView(viewJson: String, promise: Promise) {
63
+ val viewId = viewJson.getViewId()
64
+ if (viewId == -1) {
65
+ promise.reject(VIEW_ID_NOT_FOUND_IN_JSON_ERROR)
66
+ return
49
67
  }
50
- }
51
68
 
52
- override fun getCommandsMap(): MutableMap<String, Int> = mutableMapOf(
53
- CREATE_FRAGMENT_COMMAND to CREATE_FRAGMENT_COMMAND_INDEX
54
- )
69
+ val container = containers.firstOrNull { it.id == viewId }
55
70
 
56
- override fun receiveCommand(root: FrameLayout, commandId: String?, args: ReadableArray?) {
57
- if (commandId == CREATE_FRAGMENT_COMMAND) {
58
- val viewJson = args?.getString(0) ?: return
71
+ if (container == null) {
72
+ cachedCreationRequests[viewId] = CreateRequest(viewJson, promise)
73
+ return
74
+ }
59
75
 
60
- coreModule.createDataCaptureView(viewJson, NoopFrameworksResult())?.let {
61
- currentContainer?.let { container ->
62
- addDataCaptureViewToContainer(it, container)
63
- }
64
- }
76
+ coreModule.createDataCaptureView(viewJson, ReactNativeResult(promise))?.let {
77
+ addDataCaptureViewToContainer(it, container)
65
78
  }
66
79
  }
67
80
 
@@ -98,7 +111,12 @@ class DataCaptureViewManager(
98
111
  }
99
112
 
100
113
  companion object {
101
- private const val CREATE_FRAGMENT_COMMAND_INDEX = 1
102
- private const val CREATE_FRAGMENT_COMMAND = "createDataCaptureView"
114
+ private val VIEW_ID_NOT_FOUND_IN_JSON_ERROR = Error(
115
+ "Unable to add the DataCaptureView with the provided json. " +
116
+ "The json doesn't contain the viewId field."
117
+ )
103
118
  }
104
119
  }
120
+
121
+ fun String.getViewId(): Int =
122
+ JsonValue(this).getByKeyAsInt("viewId", -1)
@@ -14,7 +14,7 @@ import com.facebook.react.uimanager.ViewGroupManager
14
14
 
15
15
  abstract class ScanditViewGroupManager<T> :
16
16
  ViewGroupManager<T>() where T : ViewGroup {
17
- private val containers = mutableListOf<T>()
17
+ protected val containers = mutableListOf<T>()
18
18
 
19
19
  val currentContainer: T?
20
20
  get() = if (containers.size > 0) containers[containers.size - 1] else null