scandit-capacitor-datacapture-core 8.3.1 → 8.4.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.
@@ -17,5 +17,5 @@ Pod::Spec.new do |s|
17
17
  s.swift_version = "5.7"
18
18
 
19
19
  s.dependency "Capacitor"
20
- s.dependency "scandit-datacapture-frameworks-core", '= 8.3.1'
20
+ s.dependency "scandit-datacapture-frameworks-core", '= 8.4.0'
21
21
  end
@@ -141,14 +141,14 @@ if (ext.has('repos')) {
141
141
  }
142
142
 
143
143
  dependencies {
144
- def sdk_version = "8.3.1"
144
+ def sdk_version = "8.4.0"
145
145
 
146
146
  implementation fileTree(dir: 'libs', include: ['*.jar'])
147
147
 
148
148
  if (findProject(':scandit-datacapture-frameworks-core') != null) {
149
149
  api project(":scandit-datacapture-frameworks-core")
150
150
  } else {
151
- api "com.scandit.datacapture.frameworks:core:${safeExtGet('global_sdk_version', sdk_version)}"
151
+ api "com.scandit.datacapture.frameworks:core:${safeExtGet('frameworks_sdk_version', sdk_version)}"
152
152
  }
153
153
 
154
154
  implementation project(':capacitor-android')
@@ -16,7 +16,11 @@ import android.os.SystemClock;
16
16
  import android.view.MotionEvent;
17
17
  import android.view.View;
18
18
  import android.view.ViewGroup;
19
+ import android.view.ViewTreeObserver;
20
+ import android.view.WindowManager;
19
21
  import android.widget.FrameLayout;
22
+ import androidx.core.view.ViewCompat;
23
+ import androidx.core.view.WindowInsetsCompat;
20
24
  import com.getcapacitor.Bridge;
21
25
  import com.scandit.capacitor.datacapture.core.data.ResizeAndMoveInfo;
22
26
  import com.scandit.datacapture.core.ui.DataCaptureView;
@@ -37,6 +41,10 @@ public class DataCaptureViewHandler {
37
41
  private boolean isVisible;
38
42
  private WeakReference<DataCaptureView> dataCaptureViewReference;
39
43
  private WeakReference<View> webViewReference;
44
+ private WeakReference<FrameLayout> dcContainerReference;
45
+ private ViewTreeObserver.OnGlobalLayoutListener keyboardLayoutListener;
46
+ private int lastKnownImeHeight;
47
+ private int originalSoftInputMode;
40
48
  private View.OnTouchListener webViewTouchForwarder;
41
49
  private final List<MotionEvent> pendingTouchEvents;
42
50
  private boolean shouldForwardTouchEvents;
@@ -56,6 +64,10 @@ public class DataCaptureViewHandler {
56
64
  this.isVisible = false;
57
65
  this.dataCaptureViewReference = new WeakReference<>(null);
58
66
  this.webViewReference = new WeakReference<>(null);
67
+ this.dcContainerReference = new WeakReference<>(null);
68
+ this.keyboardLayoutListener = null;
69
+ this.lastKnownImeHeight = 0;
70
+ this.originalSoftInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED;
59
71
  this.webViewTouchForwarder = null;
60
72
  this.pendingTouchEvents = new ArrayList<>();
61
73
  this.shouldForwardTouchEvents = false;
@@ -116,6 +128,55 @@ public class DataCaptureViewHandler {
116
128
  ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
117
129
  // Add container to the same parent of the WebView
118
130
  parent.addView(dcContainer, layoutParams);
131
+ dcContainerReference = new WeakReference<>(dcContainer);
132
+
133
+ // The native overlay's spacer mechanism (shouldHandleKeyboardInsetsInternally)
134
+ // relies on WindowInsets dispatch which is broken in Capacitor (all
135
+ // versions 5.x–8.x) because CoordinatorLayout only dispatches insets
136
+ // to children with fitsSystemWindows=true. On Capacitor 8+, the
137
+ // SystemBars plugin adds an additional blocker by intercepting insets
138
+ // on the CoordinatorLayout.
139
+ //
140
+ // Instead of fighting the inset dispatch chain, directly resize the
141
+ // DataCaptureView when the keyboard appears. adjustResize makes
142
+ // OnGlobalLayoutListener fire reliably. The overlay (MATCH_PARENT
143
+ // inside DataCaptureView) shrinks with it, naturally pushing the
144
+ // bottom panel above the keyboard. No inset dispatch = no side effects.
145
+ //
146
+ // Save the original softInputMode so we can restore it when the
147
+ // DataCaptureView is removed. Setting adjustResize globally affects
148
+ // all views including the WebView, which could change how the app's
149
+ // web content handles the keyboard (e.g., if it expects adjustPan
150
+ // or adjustNothing).
151
+ originalSoftInputMode = bridge.getActivity().getWindow().getAttributes().softInputMode;
152
+ bridge
153
+ .getActivity()
154
+ .getWindow()
155
+ .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
156
+
157
+ keyboardLayoutListener =
158
+ () -> {
159
+ DataCaptureView dcView = getDataCaptureView();
160
+ if (dcView == null) return;
161
+
162
+ WindowInsetsCompat rootInsets = ViewCompat.getRootWindowInsets(dcContainer);
163
+ if (rootInsets == null) return;
164
+
165
+ int imeBottom = rootInsets.getInsets(WindowInsetsCompat.Type.ime()).bottom;
166
+ int navBottom =
167
+ rootInsets.getInsets(WindowInsetsCompat.Type.navigationBars()).bottom;
168
+ int imeHeight = Math.max(0, imeBottom - navBottom);
169
+
170
+ if (imeHeight == lastKnownImeHeight) return;
171
+ lastKnownImeHeight = imeHeight;
172
+
173
+ int originalHeight = (int) pxFromDp(latestInfo.getHeight());
174
+ ViewGroup.LayoutParams params = dcView.getLayoutParams();
175
+ params.height =
176
+ imeHeight > 0 ? Math.max(0, originalHeight - imeHeight) : originalHeight;
177
+ dcView.requestLayout();
178
+ };
179
+ dcContainer.getViewTreeObserver().addOnGlobalLayoutListener(keyboardLayoutListener);
119
180
 
120
181
  // create touch listener
121
182
  View.OnTouchListener touchForwarder =
@@ -181,17 +242,30 @@ public class DataCaptureViewHandler {
181
242
  dataCaptureViewReference = new WeakReference<>(null);
182
243
  }
183
244
  clearWebViewTouchForwarder();
184
- removeView(dataCaptureView);
245
+ removeDcContainer();
185
246
  }
186
247
 
187
- private void removeView(View view) {
188
- view.post(
189
- new Runnable() {
190
- @Override
191
- public void run() {
192
- removeFromParent(view);
248
+ private void removeDcContainer() {
249
+ FrameLayout dcContainer = dcContainerReference.get();
250
+ if (dcContainer == null) {
251
+ return;
252
+ }
253
+ if (keyboardLayoutListener != null) {
254
+ dcContainer.getViewTreeObserver().removeOnGlobalLayoutListener(keyboardLayoutListener);
255
+ keyboardLayoutListener = null;
256
+ }
257
+ // Restore the original softInputMode that was saved before we set
258
+ // adjustResize, so the app's WebView keyboard behavior is unaffected
259
+ // after the DataCaptureView is removed.
260
+ android.content.Context context = dcContainer.getContext();
261
+ dcContainer.post(
262
+ () -> {
263
+ removeFromParent(dcContainer);
264
+ if (context instanceof android.app.Activity) {
265
+ ((android.app.Activity) context).getWindow().setSoftInputMode(originalSoftInputMode);
193
266
  }
194
267
  });
268
+ dcContainerReference = new WeakReference<>(null);
195
269
  }
196
270
 
197
271
  // Update the view visibility, position and size.
@@ -211,7 +285,12 @@ public class DataCaptureViewHandler {
211
285
  view.setY(pxFromDp(latestInfo.getTop()));
212
286
  ViewGroup.LayoutParams params = view.getLayoutParams();
213
287
  params.width = (int) pxFromDp(latestInfo.getWidth());
214
- params.height = (int) pxFromDp(latestInfo.getHeight());
288
+ // Account for keyboard: if keyboard is open, reduce height.
289
+ int originalHeight = (int) pxFromDp(latestInfo.getHeight());
290
+ params.height =
291
+ lastKnownImeHeight > 0
292
+ ? Math.max(0, originalHeight - lastKnownImeHeight)
293
+ : originalHeight;
215
294
 
216
295
  View webView = getWebView();
217
296
  if (latestInfo.getShouldBeUnderWebView()) {