scandit-capacitor-datacapture-core 7.0.2 → 7.1.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/ScanditCapacitorDatacaptureCore.podspec +1 -1
- package/android/build.gradle +2 -2
- package/android/src/main/java/com/scandit/capacitor/datacapture/core/ScanditCaptureCoreNative.kt +18 -9
- package/android/src/main/java/com/scandit/capacitor/datacapture/core/handlers/DataCaptureViewHandler.kt +13 -35
- package/android/src/main/java/com/scandit/capacitor/datacapture/core/utils/CapacitorResult.kt +13 -5
- package/dist/core.js +1409 -1078
- package/dist/core.js.map +1 -1
- package/dist/dts/index.d.ts +1 -0
- package/dist/dts/ts/Capacitor/CameraProxy.d.ts +4 -4
- package/dist/dts/ts/Capacitor/Capacitor.d.ts +9 -1
- package/dist/dts/ts/Capacitor/DataCaptureContextProxy.d.ts +3 -3
- package/dist/dts/ts/Capacitor/DataCaptureViewProxy.d.ts +3 -3
- package/dist/dts/ts/Capacitor/ImageFrameSourceProxy.d.ts +2 -2
- package/dist/index.js +41 -56
- package/dist/index.js.map +1 -1
- package/ios/Plugin/CapacitorEventEmitter.swift +9 -3
- package/ios/Plugin/CapacitorResult.swift +12 -4
- package/package.json +2 -2
package/android/build.gradle
CHANGED
|
@@ -11,7 +11,7 @@ def safeExtGet(prop, fallback) {
|
|
|
11
11
|
buildscript {
|
|
12
12
|
ext {
|
|
13
13
|
kotlin_version = "1.8.20"
|
|
14
|
-
agp_version = "8.1
|
|
14
|
+
agp_version = "8.5.1"
|
|
15
15
|
}
|
|
16
16
|
repositories {
|
|
17
17
|
google()
|
|
@@ -56,7 +56,7 @@ repositories {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
dependencies {
|
|
59
|
-
def sdk_version = "7.0.
|
|
59
|
+
def sdk_version = "7.1.0-beta.1"
|
|
60
60
|
|
|
61
61
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
62
62
|
|
package/android/src/main/java/com/scandit/capacitor/datacapture/core/ScanditCaptureCoreNative.kt
CHANGED
|
@@ -22,8 +22,6 @@ import com.scandit.datacapture.frameworks.core.listeners.FrameworksDataCaptureCo
|
|
|
22
22
|
import com.scandit.datacapture.frameworks.core.listeners.FrameworksDataCaptureViewListener
|
|
23
23
|
import com.scandit.datacapture.frameworks.core.listeners.FrameworksFrameSourceDeserializer
|
|
24
24
|
import com.scandit.datacapture.frameworks.core.listeners.FrameworksFrameSourceListener
|
|
25
|
-
import com.scandit.datacapture.frameworks.core.utils.DefaultMainThread
|
|
26
|
-
import com.scandit.datacapture.frameworks.core.utils.MainThread
|
|
27
25
|
import org.json.JSONException
|
|
28
26
|
import org.json.JSONObject
|
|
29
27
|
|
|
@@ -56,7 +54,6 @@ class ScanditCaptureCoreNative :
|
|
|
56
54
|
FrameworksDataCaptureViewListener(this),
|
|
57
55
|
FrameworksFrameSourceDeserializer(frameSourceListener)
|
|
58
56
|
)
|
|
59
|
-
private val mainThread: MainThread = DefaultMainThread.getInstance()
|
|
60
57
|
private var lastFrameSourceState: FrameSourceState = FrameSourceState.OFF
|
|
61
58
|
|
|
62
59
|
private val plugins = mutableListOf<Plugin>()
|
|
@@ -83,7 +80,7 @@ class ScanditCaptureCoreNative :
|
|
|
83
80
|
}
|
|
84
81
|
}
|
|
85
82
|
|
|
86
|
-
captureViewHandler.
|
|
83
|
+
captureViewHandler.initialize(bridge.webView)
|
|
87
84
|
coreModule.onCreate(this.context)
|
|
88
85
|
}
|
|
89
86
|
|
|
@@ -106,6 +103,7 @@ class ScanditCaptureCoreNative :
|
|
|
106
103
|
|
|
107
104
|
override fun handleOnDestroy() {
|
|
108
105
|
coreModule.onDestroy()
|
|
106
|
+
captureViewHandler.disposeCurrentWebView()
|
|
109
107
|
}
|
|
110
108
|
|
|
111
109
|
private fun checkCameraPermission(): Boolean =
|
|
@@ -196,7 +194,7 @@ class ScanditCaptureCoreNative :
|
|
|
196
194
|
val jsonString = call.data.getString("context")
|
|
197
195
|
?: return call.reject(EMPTY_STRING_ERROR)
|
|
198
196
|
|
|
199
|
-
|
|
197
|
+
activity.runOnUiThread {
|
|
200
198
|
coreModule.updateContextFromJson(jsonString, CapacitorResult(call))
|
|
201
199
|
}
|
|
202
200
|
}
|
|
@@ -324,17 +322,25 @@ class ScanditCaptureCoreNative :
|
|
|
324
322
|
?: return call.reject(EMPTY_STRING_ERROR)
|
|
325
323
|
val view = coreModule.createDataCaptureView(viewJson, CapacitorResult(call))
|
|
326
324
|
if (view != null) {
|
|
327
|
-
captureViewHandler.
|
|
325
|
+
val existingView = captureViewHandler.dataCaptureView
|
|
326
|
+
if (existingView != null) {
|
|
327
|
+
// Remove existing view and add the new one.
|
|
328
|
+
coreModule.dataCaptureViewDisposed(existingView)
|
|
329
|
+
captureViewHandler.removeDataCaptureView(existingView)
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
captureViewHandler.addDataCaptureView(view, this.activity)
|
|
328
333
|
}
|
|
329
334
|
}
|
|
330
335
|
|
|
331
336
|
@PluginMethod
|
|
332
337
|
fun removeDataCaptureView(call: PluginCall) {
|
|
338
|
+
// In capacitor we just show 1 datacapture view at a time
|
|
333
339
|
val dcViewToRemove = captureViewHandler.dataCaptureView
|
|
334
340
|
if (dcViewToRemove != null) {
|
|
335
341
|
coreModule.dataCaptureViewDisposed(dcViewToRemove)
|
|
342
|
+
captureViewHandler.removeDataCaptureView(dcViewToRemove)
|
|
336
343
|
}
|
|
337
|
-
captureViewHandler.disposeCurrentDataCaptureView()
|
|
338
344
|
call.resolve()
|
|
339
345
|
}
|
|
340
346
|
|
|
@@ -346,8 +352,11 @@ class ScanditCaptureCoreNative :
|
|
|
346
352
|
}
|
|
347
353
|
|
|
348
354
|
override fun emit(eventName: String, payload: MutableMap<String, Any?>) {
|
|
349
|
-
|
|
350
|
-
|
|
355
|
+
val capacitorPayload = JSObject()
|
|
356
|
+
capacitorPayload.put("name", eventName)
|
|
357
|
+
capacitorPayload.put("data", JSONObject(payload).toString())
|
|
358
|
+
|
|
359
|
+
notifyListeners(eventName, capacitorPayload)
|
|
351
360
|
}
|
|
352
361
|
|
|
353
362
|
override fun hasListenersForEvent(eventName: String): Boolean = this.hasListeners(eventName)
|
|
@@ -10,18 +10,13 @@ import android.app.Activity
|
|
|
10
10
|
import android.graphics.Color
|
|
11
11
|
import android.view.View
|
|
12
12
|
import android.view.ViewGroup
|
|
13
|
-
import androidx.appcompat.app.AppCompatActivity
|
|
14
13
|
import com.scandit.capacitor.datacapture.core.data.ResizeAndMoveInfo
|
|
15
14
|
import com.scandit.capacitor.datacapture.core.utils.pxFromDp
|
|
16
15
|
import com.scandit.capacitor.datacapture.core.utils.removeFromParent
|
|
17
16
|
import com.scandit.datacapture.core.ui.DataCaptureView
|
|
18
|
-
import com.scandit.datacapture.frameworks.core.utils.DefaultMainThread
|
|
19
|
-
import com.scandit.datacapture.frameworks.core.utils.MainThread
|
|
20
17
|
import java.lang.ref.WeakReference
|
|
21
18
|
|
|
22
|
-
class DataCaptureViewHandler
|
|
23
|
-
private val mainThread: MainThread = DefaultMainThread.getInstance()
|
|
24
|
-
) {
|
|
19
|
+
class DataCaptureViewHandler {
|
|
25
20
|
private var latestInfo: ResizeAndMoveInfo = ResizeAndMoveInfo(0, 0, 0, 0, false)
|
|
26
21
|
private var isVisible: Boolean = false
|
|
27
22
|
private var dataCaptureViewReference: WeakReference<DataCaptureView?> = WeakReference(null)
|
|
@@ -33,17 +28,10 @@ class DataCaptureViewHandler(
|
|
|
33
28
|
val dataCaptureView: DataCaptureView?
|
|
34
29
|
get() = dataCaptureViewReference.get()
|
|
35
30
|
|
|
36
|
-
fun
|
|
37
|
-
if (this.dataCaptureViewReference.get() != dataCaptureView) {
|
|
38
|
-
disposeCurrentDataCaptureView()
|
|
39
|
-
addDataCaptureView(dataCaptureView, activity)
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
fun attachWebView(webView: View, @Suppress("UNUSED_PARAMETER") activity: AppCompatActivity) {
|
|
31
|
+
fun initialize(webView: View) {
|
|
44
32
|
if (this.webView != webView) {
|
|
45
33
|
webViewReference = WeakReference(webView)
|
|
46
|
-
|
|
34
|
+
webView.post {
|
|
47
35
|
webView.bringToFront()
|
|
48
36
|
webView.setBackgroundColor(Color.TRANSPARENT)
|
|
49
37
|
}
|
|
@@ -65,25 +53,14 @@ class DataCaptureViewHandler(
|
|
|
65
53
|
render()
|
|
66
54
|
}
|
|
67
55
|
|
|
68
|
-
|
|
69
|
-
fun disposeCurrent() {
|
|
70
|
-
disposeCurrentDataCaptureView()
|
|
71
|
-
disposeCurrentWebView()
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
fun disposeCurrentDataCaptureView() {
|
|
75
|
-
val dataCaptureView = dataCaptureViewReference.get() ?: return
|
|
76
|
-
removeDataCaptureView(dataCaptureView)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
private fun disposeCurrentWebView() {
|
|
56
|
+
fun disposeCurrentWebView() {
|
|
80
57
|
webViewReference = WeakReference(null)
|
|
81
58
|
}
|
|
82
59
|
|
|
83
|
-
|
|
60
|
+
fun addDataCaptureView(dataCaptureView: DataCaptureView, activity: Activity) {
|
|
84
61
|
dataCaptureViewReference = WeakReference(dataCaptureView)
|
|
85
62
|
|
|
86
|
-
|
|
63
|
+
activity.runOnUiThread {
|
|
87
64
|
activity.addContentView(
|
|
88
65
|
dataCaptureView,
|
|
89
66
|
ViewGroup.LayoutParams(
|
|
@@ -95,21 +72,22 @@ class DataCaptureViewHandler(
|
|
|
95
72
|
}
|
|
96
73
|
}
|
|
97
74
|
|
|
98
|
-
|
|
99
|
-
|
|
75
|
+
fun removeDataCaptureView(dataCaptureView: DataCaptureView) {
|
|
76
|
+
if (this.dataCaptureView == dataCaptureView) {
|
|
77
|
+
dataCaptureViewReference = WeakReference(null)
|
|
78
|
+
}
|
|
100
79
|
removeView(dataCaptureView)
|
|
101
80
|
}
|
|
102
81
|
|
|
103
|
-
private fun removeView(view: View
|
|
104
|
-
|
|
82
|
+
private fun removeView(view: View) {
|
|
83
|
+
view.post {
|
|
105
84
|
view.removeFromParent()
|
|
106
|
-
uiBlock?.invoke()
|
|
107
85
|
}
|
|
108
86
|
}
|
|
109
87
|
|
|
110
88
|
// Update the view visibility, position and size.
|
|
111
89
|
private fun render() {
|
|
112
|
-
val view =
|
|
90
|
+
val view = dataCaptureView ?: return
|
|
113
91
|
renderNoAnimate(view)
|
|
114
92
|
}
|
|
115
93
|
|
package/android/src/main/java/com/scandit/capacitor/datacapture/core/utils/CapacitorResult.kt
CHANGED
|
@@ -7,13 +7,21 @@ import org.json.JSONObject
|
|
|
7
7
|
|
|
8
8
|
class CapacitorResult(private val call: PluginCall) : FrameworksResult {
|
|
9
9
|
override fun success(result: Any?) {
|
|
10
|
-
if (result
|
|
11
|
-
call.resolve(JSObject.fromJSONObject(JSONObject(result)))
|
|
12
|
-
} else if (result != null) {
|
|
13
|
-
call.resolve(JSObject().putSafe("data", result))
|
|
14
|
-
} else {
|
|
10
|
+
if (result == null) {
|
|
15
11
|
call.resolve()
|
|
12
|
+
return
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
val resultData = if (result is Map<*, *>) {
|
|
16
|
+
JSONObject(result).toString()
|
|
17
|
+
} else {
|
|
18
|
+
result.toString()
|
|
16
19
|
}
|
|
20
|
+
|
|
21
|
+
val capacitorPayload = JSObject()
|
|
22
|
+
capacitorPayload.put("data", resultData)
|
|
23
|
+
|
|
24
|
+
call.resolve(capacitorPayload)
|
|
17
25
|
}
|
|
18
26
|
|
|
19
27
|
override fun error(errorCode: String, errorMessage: String?, errorDetails: Any?) {
|