@capgo/capacitor-inappbrowser 8.6.28 → 8.6.30

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.
@@ -47,10 +47,25 @@ final class SafeAreaInsetsSupport {
47
47
  }
48
48
 
49
49
  static int resolveTopMargin(boolean enabledSafeTopMargin, boolean useTopInset, int systemBarsTop, boolean appBarHandlesTopInset) {
50
+ return resolveTopMarginWithFallback(enabledSafeTopMargin, useTopInset, systemBarsTop, appBarHandlesTopInset, 0, false);
51
+ }
52
+
53
+ static int resolveTopMarginWithFallback(
54
+ boolean enabledSafeTopMargin,
55
+ boolean useTopInset,
56
+ int systemBarsTop,
57
+ boolean appBarHandlesTopInset,
58
+ int fallbackTopInset,
59
+ boolean applyFallbackWhenZero
60
+ ) {
50
61
  if (!enabledSafeTopMargin || !useTopInset || appBarHandlesTopInset) {
51
62
  return 0;
52
63
  }
53
64
 
54
- return systemBarsTop;
65
+ if (systemBarsTop > 0 || !applyFallbackWhenZero || fallbackTopInset <= 0) {
66
+ return systemBarsTop;
67
+ }
68
+
69
+ return fallbackTopInset;
55
70
  }
56
71
  }
@@ -33,6 +33,7 @@ import android.text.TextUtils;
33
33
  import android.util.Base64;
34
34
  import android.util.Log;
35
35
  import android.util.TypedValue;
36
+ import android.view.Gravity;
36
37
  import android.view.KeyEvent;
37
38
  import android.view.View;
38
39
  import android.view.ViewGroup;
@@ -61,6 +62,7 @@ import android.widget.Toast;
61
62
  import android.widget.Toolbar;
62
63
  import androidx.activity.result.ActivityResult;
63
64
  import androidx.activity.result.contract.ActivityResultContracts;
65
+ import androidx.coordinatorlayout.widget.CoordinatorLayout;
64
66
  import androidx.core.content.FileProvider;
65
67
  import androidx.core.graphics.Insets;
66
68
  import androidx.core.view.ViewCompat;
@@ -2575,8 +2577,13 @@ public class WebViewDialog extends Dialog implements ProxyResponseRouting.ProxyR
2575
2577
  }
2576
2578
  }
2577
2579
 
2580
+ boolean isBlankToolbar = _options != null && TextUtils.equals(_options.getToolbarType(), "blank");
2581
+ if (isBlankToolbar) {
2582
+ configureBlankToolbarLayout();
2583
+ }
2584
+
2578
2585
  // Special handling for Android 15+
2579
- if (isAndroid15Plus) {
2586
+ if (isAndroid15Plus && !isBlankToolbar) {
2580
2587
  // Get AppBarLayout which contains the toolbar
2581
2588
  if (toolbarView != null && toolbarView.getParent() instanceof com.google.android.material.appbar.AppBarLayout appBarLayout) {
2582
2589
  // Remove elevation to eliminate shadows (only on Android 15+)
@@ -2751,18 +2758,76 @@ public class WebViewDialog extends Dialog implements ProxyResponseRouting.ProxyR
2751
2758
  _options.getEnabledSafeMargin()
2752
2759
  );
2753
2760
  int imeBottom = keyboardVisible ? ime.bottom : 0;
2754
- int navTop = SafeAreaInsetsSupport.resolveTopMargin(
2761
+ boolean applyTopFallback = _options.getEnabledSafeTopMargin() && _options.getUseTopInset();
2762
+ int fallbackTopInset = applyTopFallback ? getSystemStatusBarHeight() : 0;
2763
+ int navTop = SafeAreaInsetsSupport.resolveTopMarginWithFallback(
2755
2764
  _options.getEnabledSafeTopMargin(),
2756
2765
  _options.getUseTopInset(),
2757
2766
  bars.top,
2758
- appBarHandlesTopInset
2767
+ appBarHandlesTopInset,
2768
+ fallbackTopInset,
2769
+ applyTopFallback
2759
2770
  );
2771
+ int bottomMargin = SafeAreaInsetsSupport.resolveBottomMargin(_options.getEnabledSafeMargin(), safeBottomInset, imeBottom);
2760
2772
 
2761
2773
  mlp.topMargin = navTop;
2762
- mlp.bottomMargin = SafeAreaInsetsSupport.resolveBottomMargin(_options.getEnabledSafeMargin(), safeBottomInset, imeBottom);
2774
+ mlp.bottomMargin = bottomMargin;
2763
2775
  mlp.leftMargin = bars.left;
2764
2776
  mlp.rightMargin = bars.right;
2765
2777
  _webView.setLayoutParams(mlp);
2778
+ injectSafeAreaCssVariables(navTop, bottomMargin, bars.left, bars.right);
2779
+ }
2780
+
2781
+ private void configureBlankToolbarLayout() {
2782
+ View appBarLayout = findViewById(R.id.app_bar_layout);
2783
+ if (appBarLayout != null) {
2784
+ appBarLayout.setVisibility(View.GONE);
2785
+ }
2786
+
2787
+ View statusBarColorView = findViewById(R.id.status_bar_color_view);
2788
+ if (statusBarColorView != null) {
2789
+ statusBarColorView.setVisibility(View.GONE);
2790
+ }
2791
+
2792
+ View contentBrowserLayout = findViewById(R.id.content_browser_layout);
2793
+ if (contentBrowserLayout != null && contentBrowserLayout.getLayoutParams() instanceof CoordinatorLayout.LayoutParams) {
2794
+ CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) contentBrowserLayout.getLayoutParams();
2795
+ layoutParams.setBehavior(null);
2796
+ contentBrowserLayout.setLayoutParams(layoutParams);
2797
+ }
2798
+ }
2799
+
2800
+ private int getSystemStatusBarHeight() {
2801
+ int resourceId = getContext().getResources().getIdentifier("status_bar_height", "dimen", "android");
2802
+ if (resourceId <= 0) {
2803
+ return 0;
2804
+ }
2805
+
2806
+ return getContext().getResources().getDimensionPixelSize(resourceId);
2807
+ }
2808
+
2809
+ private void injectSafeAreaCssVariables(int top, int bottom, int left, int right) {
2810
+ if (_webView == null) {
2811
+ return;
2812
+ }
2813
+
2814
+ String script = String.format(
2815
+ Locale.US,
2816
+ "(function(){var root=document.documentElement;" +
2817
+ "root.style.setProperty('--safe-area-inset-top','%dpx');" +
2818
+ "root.style.setProperty('--safe-area-inset-bottom','%dpx');" +
2819
+ "root.style.setProperty('--safe-area-inset-left','%dpx');" +
2820
+ "root.style.setProperty('--safe-area-inset-right','%dpx');})();",
2821
+ top,
2822
+ bottom,
2823
+ left,
2824
+ right
2825
+ );
2826
+ _webView.post(() -> {
2827
+ if (_webView != null) {
2828
+ _webView.evaluateJavascript(script, null);
2829
+ }
2830
+ });
2766
2831
  }
2767
2832
 
2768
2833
  private View resolveSafeAreaInsetsSourceView() {
@@ -3594,6 +3659,8 @@ public class WebViewDialog extends Dialog implements ProxyResponseRouting.ProxyR
3594
3659
  // Status bar color is already set at the top of this method, no need to set again
3595
3660
  } else if (TextUtils.equals(_options.getToolbarType(), "blank")) {
3596
3661
  _toolbar.setVisibility(View.GONE);
3662
+ configureBlankToolbarLayout();
3663
+ requestSafeAreaInsets();
3597
3664
 
3598
3665
  // Also set window background color to match status bar for blank toolbar
3599
3666
  View statusBarColorView = findViewById(R.id.status_bar_color_view);
@@ -5990,12 +6057,14 @@ public class WebViewDialog extends Dialog implements ProxyResponseRouting.ProxyR
5990
6057
  params.height = (int) getPixels(height);
5991
6058
  params.x = (x != null) ? (int) getPixels(x) : 0;
5992
6059
  params.y = (y != null) ? (int) getPixels(y) : 0;
6060
+ params.gravity = Gravity.TOP | Gravity.START;
5993
6061
  } else if (height != null && width == null) {
5994
6062
  // If only height is specified, use custom height with fullscreen width
5995
6063
  params.width = WindowManager.LayoutParams.MATCH_PARENT;
5996
6064
  params.height = (int) getPixels(height);
5997
6065
  params.x = 0;
5998
6066
  params.y = (y != null) ? (int) getPixels(y) : 0;
6067
+ params.gravity = Gravity.TOP | Gravity.START;
5999
6068
  } else {
6000
6069
  // Default to fullscreen
6001
6070
  params.width = WindowManager.LayoutParams.MATCH_PARENT;
@@ -98,7 +98,7 @@ public class CapgoInAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
98
98
  case aware = "AWARE"
99
99
  case fakeVisible = "FAKE_VISIBLE"
100
100
  }
101
- private let pluginVersion: String = "8.6.28"
101
+ private let pluginVersion: String = "8.6.30"
102
102
  public let identifier = "CapgoInAppBrowserPlugin"
103
103
  public let jsName = "CapgoInAppBrowser"
104
104
  public let pluginMethods: [CAPPluginMethod] = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-inappbrowser",
3
- "version": "8.6.28",
3
+ "version": "8.6.30",
4
4
  "description": "Capacitor plugin in app browser",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",