@capgo/inappbrowser 7.6.0 → 7.6.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.
@@ -18,11 +18,13 @@ import android.graphics.PorterDuff;
18
18
  import android.graphics.PorterDuffColorFilter;
19
19
  import android.net.Uri;
20
20
  import android.net.http.SslError;
21
+ import android.os.Build;
21
22
  import android.text.TextUtils;
22
23
  import android.util.Base64;
23
24
  import android.util.Log;
24
25
  import android.util.TypedValue;
25
26
  import android.view.View;
27
+ import android.view.ViewGroup;
26
28
  import android.view.Window;
27
29
  import android.view.WindowManager;
28
30
  import android.webkit.HttpAuthHandler;
@@ -41,6 +43,9 @@ import android.widget.ImageView;
41
43
  import android.widget.TextView;
42
44
  import android.widget.Toast;
43
45
  import android.widget.Toolbar;
46
+ import androidx.core.graphics.Insets;
47
+ import androidx.core.view.ViewCompat;
48
+ import androidx.core.view.WindowInsetsCompat;
44
49
  import androidx.core.view.WindowInsetsControllerCompat;
45
50
  import com.caverock.androidsvg.SVG;
46
51
  import com.caverock.androidsvg.SVGParseException;
@@ -291,6 +296,10 @@ public class WebViewDialog extends Dialog {
291
296
  );
292
297
 
293
298
  this._webView = findViewById(R.id.browser_view);
299
+
300
+ // Apply insets to fix edge-to-edge issues on Android 15+
301
+ applyInsets();
302
+
294
303
  _webView.addJavascriptInterface(
295
304
  new JavaScriptInterface(),
296
305
  "AndroidInterface"
@@ -445,6 +454,205 @@ public class WebViewDialog extends Dialog {
445
454
  }
446
455
  }
447
456
 
457
+ /**
458
+ * Apply window insets to the WebView to properly handle edge-to-edge display
459
+ * and fix status bar overlap issues on Android 15+
460
+ */
461
+ private void applyInsets() {
462
+ if (_webView == null) {
463
+ return;
464
+ }
465
+
466
+ // Check if we need Android 15+ specific fixes
467
+ boolean isAndroid15Plus = Build.VERSION.SDK_INT >= 35;
468
+
469
+ // Get parent view
470
+ ViewGroup parent = (ViewGroup) _webView.getParent();
471
+
472
+ // Find status bar color view and toolbar for Android 15+ specific handling
473
+ View statusBarColorView = findViewById(R.id.status_bar_color_view);
474
+ View toolbarView = findViewById(R.id.tool_bar);
475
+
476
+ // Special handling for Android 15+
477
+ if (isAndroid15Plus) {
478
+ // Get AppBarLayout which contains the toolbar
479
+ if (
480
+ toolbarView != null &&
481
+ toolbarView.getParent() instanceof
482
+ com.google.android.material.appbar.AppBarLayout
483
+ ) {
484
+ com.google.android.material.appbar.AppBarLayout appBarLayout =
485
+ (com.google.android.material.appbar.AppBarLayout) toolbarView.getParent();
486
+
487
+ // Remove elevation to eliminate shadows (only on Android 15+)
488
+ appBarLayout.setElevation(0);
489
+ appBarLayout.setStateListAnimator(null);
490
+ appBarLayout.setOutlineProvider(null);
491
+
492
+ // Determine background color to use
493
+ int backgroundColor = Color.BLACK; // Default fallback
494
+ if (
495
+ _options.getToolbarColor() != null &&
496
+ !_options.getToolbarColor().isEmpty()
497
+ ) {
498
+ try {
499
+ backgroundColor = Color.parseColor(_options.getToolbarColor());
500
+ } catch (IllegalArgumentException e) {
501
+ Log.e(
502
+ "InAppBrowser",
503
+ "Invalid toolbar color, using black: " + e.getMessage()
504
+ );
505
+ }
506
+ } else {
507
+ // Follow system theme if no color specified
508
+ boolean isDarkTheme = isDarkThemeEnabled();
509
+ backgroundColor = isDarkTheme ? Color.BLACK : Color.WHITE;
510
+ }
511
+
512
+ // Apply fixes for Android 15+ using a delayed post
513
+ final int finalBgColor = backgroundColor;
514
+ _webView.post(() -> {
515
+ // Get status bar height
516
+ int statusBarHeight = 0;
517
+ int resourceId = getContext()
518
+ .getResources()
519
+ .getIdentifier("status_bar_height", "dimen", "android");
520
+ if (resourceId > 0) {
521
+ statusBarHeight = getContext()
522
+ .getResources()
523
+ .getDimensionPixelSize(resourceId);
524
+ }
525
+
526
+ // Fix status bar view
527
+ if (statusBarColorView != null) {
528
+ ViewGroup.LayoutParams params =
529
+ statusBarColorView.getLayoutParams();
530
+ params.height = statusBarHeight;
531
+ statusBarColorView.setLayoutParams(params);
532
+ statusBarColorView.setBackgroundColor(finalBgColor);
533
+ statusBarColorView.setVisibility(View.VISIBLE);
534
+ }
535
+
536
+ // Fix AppBarLayout position
537
+ ViewGroup.MarginLayoutParams params =
538
+ (ViewGroup.MarginLayoutParams) appBarLayout.getLayoutParams();
539
+ params.topMargin = statusBarHeight;
540
+ appBarLayout.setLayoutParams(params);
541
+ appBarLayout.setBackgroundColor(finalBgColor);
542
+ });
543
+ }
544
+ }
545
+
546
+ // Apply system insets to WebView (compatible with all Android versions)
547
+ ViewCompat.setOnApplyWindowInsetsListener(_webView, (v, windowInsets) -> {
548
+ Insets insets = windowInsets.getInsets(
549
+ WindowInsetsCompat.Type.systemBars()
550
+ );
551
+ Boolean keyboardVisible = windowInsets.isVisible(
552
+ WindowInsetsCompat.Type.ime()
553
+ );
554
+
555
+ ViewGroup.MarginLayoutParams mlp =
556
+ (ViewGroup.MarginLayoutParams) v.getLayoutParams();
557
+
558
+ // Apply margins based on Android version
559
+ if (isAndroid15Plus) {
560
+ // Android 15+ specific handling
561
+ if (keyboardVisible) {
562
+ mlp.bottomMargin = 0;
563
+ } else {
564
+ mlp.bottomMargin = insets.bottom;
565
+ }
566
+ // On Android 15+, don't add top margin as it's handled by AppBarLayout
567
+ mlp.topMargin = 0;
568
+ } else {
569
+ // Original behavior for older Android versions
570
+ mlp.topMargin = insets.top;
571
+ mlp.bottomMargin = insets.bottom;
572
+ }
573
+
574
+ // These stay the same for all Android versions
575
+ mlp.leftMargin = insets.left;
576
+ mlp.rightMargin = insets.right;
577
+ v.setLayoutParams(mlp);
578
+
579
+ return WindowInsetsCompat.CONSUMED;
580
+ });
581
+
582
+ // Handle window decoration - version-specific window settings
583
+ if (getWindow() != null) {
584
+ if (isAndroid15Plus) {
585
+ // Only for Android 15+: Set window to draw behind status bar
586
+ getWindow().setDecorFitsSystemWindows(false);
587
+ getWindow().setStatusBarColor(Color.TRANSPARENT);
588
+
589
+ // Set status bar text color
590
+ int backgroundColor;
591
+ if (
592
+ _options.getToolbarColor() != null &&
593
+ !_options.getToolbarColor().isEmpty()
594
+ ) {
595
+ try {
596
+ backgroundColor = Color.parseColor(_options.getToolbarColor());
597
+ boolean isDarkBackground = isDarkColor(backgroundColor);
598
+ WindowInsetsControllerCompat controller =
599
+ new WindowInsetsControllerCompat(
600
+ getWindow(),
601
+ getWindow().getDecorView()
602
+ );
603
+ controller.setAppearanceLightStatusBars(!isDarkBackground);
604
+ } catch (IllegalArgumentException e) {
605
+ // Ignore color parsing errors
606
+ }
607
+ }
608
+ } else if (Build.VERSION.SDK_INT >= 30) {
609
+ // Android 11-14: Use original behavior
610
+ WindowInsetsControllerCompat controller =
611
+ new WindowInsetsControllerCompat(
612
+ getWindow(),
613
+ getWindow().getDecorView()
614
+ );
615
+
616
+ // Original behavior for status bar color
617
+ if (
618
+ _options.getToolbarColor() != null &&
619
+ !_options.getToolbarColor().isEmpty()
620
+ ) {
621
+ try {
622
+ int toolbarColor = Color.parseColor(_options.getToolbarColor());
623
+ getWindow().setStatusBarColor(toolbarColor);
624
+
625
+ boolean isDarkBackground = isDarkColor(toolbarColor);
626
+ controller.setAppearanceLightStatusBars(!isDarkBackground);
627
+ } catch (IllegalArgumentException e) {
628
+ // Ignore color parsing errors
629
+ }
630
+ }
631
+ } else {
632
+ // Pre-Android 11: Original behavior with deprecated flags
633
+ getWindow()
634
+ .getDecorView()
635
+ .setSystemUiVisibility(
636
+ View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
637
+ View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
638
+ );
639
+
640
+ // Apply original status bar color logic
641
+ if (
642
+ _options.getToolbarColor() != null &&
643
+ !_options.getToolbarColor().isEmpty()
644
+ ) {
645
+ try {
646
+ int toolbarColor = Color.parseColor(_options.getToolbarColor());
647
+ getWindow().setStatusBarColor(toolbarColor);
648
+ } catch (IllegalArgumentException e) {
649
+ // Ignore color parsing errors
650
+ }
651
+ }
652
+ }
653
+ }
654
+ }
655
+
448
656
  public void postMessageToJS(Object detail) {
449
657
  if (_webView != null) {
450
658
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/inappbrowser",
3
- "version": "7.6.0",
3
+ "version": "7.6.1",
4
4
  "description": "Capacitor plugin in app browser",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",