scandit-capacitor-datacapture-barcode 7.4.1 → 7.5.0-beta.2

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 (27) hide show
  1. package/ScanditCapacitorDatacaptureBarcode.podspec +1 -1
  2. package/android/build.gradle +1 -1
  3. package/android/src/main/java/com/scandit/capacitor/datacapture/barcode/ScanditBarcodeNative.kt +225 -148
  4. package/android/src/main/java/com/scandit/capacitor/datacapture/barcode/count/BarcodeCountViewHandler.kt +4 -4
  5. package/android/src/main/java/com/scandit/capacitor/datacapture/barcode/find/BarcodeFindViewHandler.kt +90 -71
  6. package/android/src/main/java/com/scandit/capacitor/datacapture/barcode/utils/AdvancedOverlayViewSerialization.kt +7 -4
  7. package/dist/barcode.js +2878 -1364
  8. package/dist/barcode.js.map +1 -1
  9. package/dist/dts/definitions.d.ts +0 -35
  10. package/dist/dts/ts/BarcodeCountView.d.ts +1 -0
  11. package/dist/dts/ts/BarcodePickView.d.ts +3 -0
  12. package/dist/dts/ts/Capacitor/Capacitor.d.ts +0 -14
  13. package/dist/dts/web.d.ts +1 -2
  14. package/dist/index.js +40 -373
  15. package/dist/index.js.map +1 -1
  16. package/ios/Plugin/BarcodeCountViewHandler.swift +4 -4
  17. package/ios/Plugin/BarcodePickViewHandler.swift +4 -4
  18. package/ios/Plugin/CommandJSONArgument+ScanditBarcodeCapture.swift +12 -9
  19. package/ios/Plugin/Plugin.m +11 -8
  20. package/ios/Plugin/ScanditBarcodeCapture.swift +493 -169
  21. package/package.json +4 -4
  22. package/dist/dts/ts/Capacitor/BarcodeBatchAdvancedOverlayProxy.d.ts +0 -23
  23. package/dist/dts/ts/Capacitor/BarcodeBatchBasicOverlayProxy.d.ts +0 -14
  24. package/dist/dts/ts/Capacitor/BarcodeBatchListenerProxy.d.ts +0 -15
  25. package/dist/dts/ts/Capacitor/BarcodeCountViewProxy.d.ts +0 -7
  26. package/dist/dts/ts/Capacitor/BarcodeFindListenerProxy.d.ts +0 -18
  27. package/dist/dts/ts/Capacitor/BarcodeFindViewProxy.d.ts +0 -18
@@ -26,14 +26,14 @@ internal class BarcodeCountViewHandler (
26
26
  private var barcodeCountViewReference: WeakReference<BarcodeCountView>? = null
27
27
  private var webViewReference: WeakReference<View>? = null
28
28
 
29
- val barcodeCountView: BarcodeCountView?
29
+ val currentBarcodeCountView: BarcodeCountView?
30
30
  get() = barcodeCountViewReference?.get()
31
31
 
32
32
  private val webView: View?
33
33
  get() = webViewReference?.get()
34
34
 
35
35
  fun attachBarcodeCountView(barcodeCountView: BarcodeCountView, activity: AppCompatActivity) {
36
- if (this.barcodeCountView != barcodeCountView) {
36
+ if (this.currentBarcodeCountView != barcodeCountView) {
37
37
  disposeCurrentView()
38
38
  addBarcodeCountView(barcodeCountView, activity)
39
39
  }
@@ -68,7 +68,7 @@ internal class BarcodeCountViewHandler (
68
68
  }
69
69
 
70
70
  fun disposeCurrentView() {
71
- val view = barcodeCountView ?: return
71
+ val view = currentBarcodeCountView ?: return
72
72
  removeBarcodeCountView(view)
73
73
  }
74
74
 
@@ -111,7 +111,7 @@ internal class BarcodeCountViewHandler (
111
111
 
112
112
  // Update the view visibility, position and size.
113
113
  fun render() {
114
- val view = barcodeCountView ?: return
114
+ val view = currentBarcodeCountView ?: return
115
115
  renderNoAnimate(view)
116
116
  }
117
117
 
@@ -12,72 +12,101 @@ import android.view.View
12
12
  import android.view.ViewGroup
13
13
  import android.widget.FrameLayout
14
14
  import androidx.appcompat.app.AppCompatActivity
15
- import androidx.core.view.children
16
- import com.scandit.capacitor.datacapture.core.data.ResizeAndMoveInfo
17
- import com.scandit.capacitor.datacapture.core.utils.pxFromDp
18
15
  import com.scandit.capacitor.datacapture.core.utils.removeFromParent
19
- import com.scandit.datacapture.barcode.find.ui.BarcodeFindView
20
16
  import com.scandit.datacapture.frameworks.core.utils.DefaultMainThread
21
17
  import com.scandit.datacapture.frameworks.core.utils.MainThread
22
18
  import java.lang.ref.WeakReference
19
+ import java.util.concurrent.ConcurrentHashMap
23
20
 
24
21
  class BarcodeFindViewHandler(
25
22
  private val mainThread: MainThread = DefaultMainThread.getInstance()
26
23
  ) {
27
- private var latestInfo: ResizeAndMoveInfo = ResizeAndMoveInfo(0, 0, 600, 600, false)
28
- private var isVisible: Boolean = true
29
- private var barcodeFindViewContainerReference: WeakReference<FrameLayout>? = null
30
- private var webViewReference: WeakReference<View>? = null
24
+ private val containers: MutableMap<Int, WeakReference<FrameLayout>> = ConcurrentHashMap()
25
+ private val containerVisibility: MutableMap<Int, Boolean> = ConcurrentHashMap()
31
26
 
32
- val barcodeFindViewContainer: FrameLayout?
33
- get() = barcodeFindViewContainerReference?.get()
27
+ private var webViewReference: WeakReference<View>? = null
34
28
 
35
29
  private val webView: View?
36
- get() = webViewReference?.get()
37
-
30
+ get() = webViewReference?.get()
38
31
 
39
- fun prepareContainer(context: Context) : FrameLayout {
40
- return FrameLayout(context)
32
+ fun prepareContainer(context: Context): FrameLayout {
33
+ return FrameLayout(
34
+ context
35
+ )
41
36
  }
42
37
 
43
- fun addBarcodeFindViewContainer(container: FrameLayout, activity: AppCompatActivity) {
44
- if (this.barcodeFindViewContainer != container) {
45
- disposeCurrentView()
46
- addContainer(container, activity)
38
+ fun addBarcodeFindViewContainer(viewId: Int, container: FrameLayout, activity: AppCompatActivity) {
39
+ if (containers.containsKey(viewId)) {
40
+ val existingContainer = containers.remove(viewId)?.get()
41
+ if (existingContainer != null) {
42
+ removeView(existingContainer)
43
+ }
47
44
  }
45
+
46
+ containers[viewId] = WeakReference(container)
47
+ containerVisibility[viewId] = true
48
+
49
+ addContainer(
50
+ viewId,
51
+ container,
52
+ activity
53
+ )
48
54
  }
49
55
 
50
56
  fun attachWebView(webView: View) {
51
57
  if (this.webView != webView) {
52
58
  webViewReference = WeakReference(webView)
53
- webView.bringToFront()
54
- webView.setBackgroundColor(Color.TRANSPARENT)
59
+ mainThread.runOnMainThread {
60
+ webView.bringToFront()
61
+ webView.setBackgroundColor(Color.TRANSPARENT)
62
+ }
55
63
  }
56
64
  }
57
65
 
58
- fun setVisible() {
59
- isVisible = true
60
- render()
66
+ fun setVisible(viewId: Int) {
67
+ mainThread.runOnMainThread {
68
+ containerVisibility[viewId] = true
69
+ renderNoAnimate(
70
+ containers[viewId]?.get() ?: return@runOnMainThread,
71
+ containerVisibility[viewId] == true
72
+ )
73
+ }
61
74
  }
62
75
 
63
- fun setInvisible() {
64
- isVisible = false
65
- render()
76
+ fun setInvisible(viewId: Int) {
77
+ mainThread.runOnMainThread {
78
+ containerVisibility[viewId] = false
79
+ renderNoAnimate(
80
+ containers[viewId]?.get() ?: return@runOnMainThread,
81
+ containerVisibility[viewId] == true
82
+ )
83
+ }
66
84
  }
67
85
 
68
- fun setResizeAndMoveInfo(info: ResizeAndMoveInfo) {
69
- latestInfo = info
70
- render()
71
- }
86
+ fun disposeContainer(viewId: Int) {
87
+ mainThread.runOnMainThread {
88
+ containers.remove(viewId)?.get()?.also {
89
+ removeView(it)
90
+ }
91
+ }
72
92
 
73
- fun disposeCurrent() {
74
- disposeCurrentView()
75
- disposeCurrentWebView()
93
+ containerVisibility.remove(viewId)
94
+
95
+ if (containers.isEmpty()) {
96
+ mainThread.runOnMainThread {
97
+ setWebViewVisible()
98
+ }
99
+ }
76
100
  }
77
101
 
78
- fun disposeCurrentView() {
79
- val view = barcodeFindViewContainer ?: return
80
- removeView(view)
102
+ fun disposeAll() {
103
+ mainThread.runOnMainThread {
104
+ for (viewId in containers.keys) {
105
+ disposeContainer(viewId)
106
+ }
107
+
108
+ disposeCurrentWebView()
109
+ }
81
110
  }
82
111
 
83
112
  private fun disposeCurrentWebView() {
@@ -85,60 +114,50 @@ class BarcodeFindViewHandler(
85
114
  }
86
115
 
87
116
  private fun addContainer(
88
- barcodeFindViewContainer: FrameLayout,
117
+ viewId: Int,
118
+ container: FrameLayout,
89
119
  activity: AppCompatActivity
90
120
  ) {
91
- barcodeFindViewContainerReference = WeakReference(barcodeFindViewContainer)
92
-
93
121
  mainThread.runOnMainThread {
94
122
  activity.addContentView(
95
- barcodeFindViewContainer,
123
+ container,
96
124
  ViewGroup.LayoutParams(
97
125
  ViewGroup.LayoutParams.MATCH_PARENT,
98
126
  ViewGroup.LayoutParams.MATCH_PARENT
99
127
  )
100
128
  )
101
- render()
129
+ renderNoAnimate(container, containerVisibility[viewId] == true)
102
130
  }
103
131
  }
104
132
 
105
- private fun removeBarcodeFindViewContainer(barcodeFindViewContainer: FrameLayout) {
106
- barcodeFindViewContainerReference = null
107
- removeView(barcodeFindViewContainer) {
108
- (barcodeFindViewContainer.children.firstOrNull() as? BarcodeFindView)?.setListener(null)
133
+ private fun removeView(view: View) {
134
+ mainThread.runOnMainThread {
135
+ view.removeFromParent()
109
136
  }
110
137
  }
111
138
 
112
- private fun removeView(view: View, uiBlock: (() -> Unit)? = null) {
113
- mainThread.runOnMainThread {
114
- view.removeFromParent()
115
- uiBlock?.invoke()
139
+ private fun renderNoAnimate(container: FrameLayout, isVisible: Boolean) {
140
+ container.visibility = if (isVisible) View.VISIBLE else View.GONE
141
+ container.layoutParams.apply {
142
+ width = ViewGroup.LayoutParams.MATCH_PARENT
143
+ height = ViewGroup.LayoutParams.MATCH_PARENT
144
+ }
145
+ if (isVisible) {
146
+ container.bringToFront()
147
+ setWebViewInvisible()
148
+ } else {
149
+ setWebViewVisible()
116
150
  }
151
+ container.requestLayout()
152
+
117
153
  }
118
154
 
119
- // Update the view visibility, position and size.
120
- fun render() {
121
- val view = barcodeFindViewContainer ?: return
122
- renderNoAnimate(view)
155
+ private fun setWebViewVisible() {
156
+ webView?.bringToFront()
157
+ (webView?.parent as View).translationZ = 1F
123
158
  }
124
159
 
125
- private fun renderNoAnimate(barcodeFindViewContainer: FrameLayout) {
126
- barcodeFindViewContainer.post {
127
- barcodeFindViewContainer.visibility = if (isVisible) View.VISIBLE else View.GONE
128
- barcodeFindViewContainer.x = latestInfo.left.pxFromDp()
129
- barcodeFindViewContainer.y = latestInfo.top.pxFromDp()
130
- barcodeFindViewContainer.layoutParams.apply {
131
- width = ViewGroup.LayoutParams.MATCH_PARENT
132
- height = ViewGroup.LayoutParams.MATCH_PARENT
133
- }
134
- if (latestInfo.shouldBeUnderWebView) {
135
- webView?.bringToFront()
136
- (webView?.parent as View).translationZ = 1F
137
- } else {
138
- barcodeFindViewContainer.bringToFront()
139
- (webView?.parent as View).translationZ = -1F
140
- }
141
- barcodeFindViewContainer.requestLayout()
142
- }
160
+ private fun setWebViewInvisible() {
161
+ (webView?.parent as View).translationZ = -1F
143
162
  }
144
163
  }
@@ -6,7 +6,8 @@ import org.json.JSONObject
6
6
  data class SerializableAdvancedOverlayViewData(
7
7
  val view: SerializableAdvancedOverlayView?,
8
8
  val trackedBarcodeId: Int,
9
- val sessionFrameSequenceId: Long?
9
+ val sessionFrameSequenceId: Long?,
10
+ val dataCaptureViewId: Int
10
11
  ) {
11
12
  constructor(json: JSONObject) : this(
12
13
  view = SerializableAdvancedOverlayView.fromJson(json.optJSONObject(FIELD_VIEW)),
@@ -15,7 +16,8 @@ data class SerializableAdvancedOverlayViewData(
15
16
  json[FIELD_FRAME_SEQUENCE_ID] is Long
16
17
  ) {
17
18
  json.getLong(FIELD_FRAME_SEQUENCE_ID)
18
- } else null
19
+ } else null,
20
+ dataCaptureViewId = json.getInt(FIELD_DATA_CAPTURE_VIEW_ID),
19
21
  )
20
22
  }
21
23
 
@@ -79,6 +81,7 @@ data class SerializableAdvancedOverlayViewOptions(
79
81
  }
80
82
  }
81
83
 
82
- private const val FIELD_VIEW = "view"
83
- private const val FIELD_TRACKED_BARCODE_ID = "trackedBarcodeID"
84
+ private const val FIELD_VIEW = "viewJson"
85
+ private const val FIELD_TRACKED_BARCODE_ID = "trackedBarcodeIdentifier"
86
+ private const val FIELD_DATA_CAPTURE_VIEW_ID = "dataCaptureViewId"
84
87
  private const val FIELD_FRAME_SEQUENCE_ID = "sessionFrameSequenceID"