@capgo/capacitor-inappbrowser 8.22.1 → 8.22.3

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.
@@ -4,7 +4,6 @@ import android.os.Build;
4
4
  import android.view.View;
5
5
  import android.view.Window;
6
6
  import android.view.WindowManager;
7
- import androidx.core.view.ViewCompat;
8
7
  import androidx.core.view.WindowInsetsCompat;
9
8
  import androidx.core.view.WindowInsetsControllerCompat;
10
9
 
@@ -14,26 +13,14 @@ final class FullscreenWindowState {
14
13
  private final Window window;
15
14
  private final WindowManager.LayoutParams attributes = new WindowManager.LayoutParams();
16
15
  private final int visibility;
17
- private final int behavior;
18
- private final boolean statusVisible;
19
- private final boolean navigationVisible;
16
+ private final SystemBarsControllerState systemBars;
20
17
 
21
18
  FullscreenWindowState(Window window) {
22
19
  this.window = window;
23
20
  attributes.copyFrom(window.getAttributes());
24
21
  View decor = window.getDecorView();
25
22
  visibility = decor.getSystemUiVisibility();
26
- WindowInsetsControllerCompat controller = new WindowInsetsControllerCompat(window, decor);
27
- behavior = controller.getSystemBarsBehavior();
28
- WindowInsetsCompat insets = ViewCompat.getRootWindowInsets(decor);
29
- statusVisible =
30
- insets != null
31
- ? insets.isVisible(WindowInsetsCompat.Type.statusBars())
32
- : (attributes.flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0;
33
- navigationVisible =
34
- insets != null
35
- ? insets.isVisible(WindowInsetsCompat.Type.navigationBars())
36
- : (visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
23
+ systemBars = SystemBarsControllerState.capture(window);
37
24
  }
38
25
 
39
26
  void enter() {
@@ -60,12 +47,7 @@ final class FullscreenWindowState {
60
47
  }
61
48
 
62
49
  void restore() {
63
- WindowInsetsControllerCompat controller = new WindowInsetsControllerCompat(window, window.getDecorView());
64
- if (statusVisible) controller.show(WindowInsetsCompat.Type.statusBars());
65
- else controller.hide(WindowInsetsCompat.Type.statusBars());
66
- if (navigationVisible) controller.show(WindowInsetsCompat.Type.navigationBars());
67
- else controller.hide(WindowInsetsCompat.Type.navigationBars());
68
- controller.setSystemBarsBehavior(behavior);
50
+ systemBars.applyTo(window);
69
51
  window.setAttributes(attributes);
70
52
  window.getDecorView().setSystemUiVisibility(visibility);
71
53
  }
@@ -0,0 +1,76 @@
1
+ package ee.forgr.capacitor_inappbrowser;
2
+
3
+ import android.view.View;
4
+ import android.view.Window;
5
+ import android.view.WindowManager;
6
+ import androidx.core.view.ViewCompat;
7
+ import androidx.core.view.WindowInsetsCompat;
8
+ import androidx.core.view.WindowInsetsControllerCompat;
9
+
10
+ /** Captures status/navigation bar visibility and transient behavior for one window. */
11
+ final class SystemBarsControllerState {
12
+
13
+ private final int behavior;
14
+ private final boolean statusVisible;
15
+ private final boolean navigationVisible;
16
+
17
+ SystemBarsControllerState(int behavior, boolean statusVisible, boolean navigationVisible) {
18
+ this.behavior = behavior;
19
+ this.statusVisible = statusVisible;
20
+ this.navigationVisible = navigationVisible;
21
+ }
22
+
23
+ static SystemBarsControllerState capture(Window window) {
24
+ if (window == null) {
25
+ return new SystemBarsControllerState(WindowInsetsControllerCompat.BEHAVIOR_DEFAULT, true, true);
26
+ }
27
+
28
+ View decor = window.getDecorView();
29
+ WindowInsetsControllerCompat controller = new WindowInsetsControllerCompat(window, decor);
30
+ int behavior = controller.getSystemBarsBehavior();
31
+ WindowInsetsCompat insets = ViewCompat.getRootWindowInsets(decor);
32
+ WindowManager.LayoutParams attributes = window.getAttributes();
33
+ int visibility = decor.getSystemUiVisibility();
34
+ boolean statusVisible =
35
+ insets != null
36
+ ? insets.isVisible(WindowInsetsCompat.Type.statusBars()) && (visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
37
+ : (attributes.flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0 &&
38
+ (visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0;
39
+ boolean navigationVisible =
40
+ insets != null
41
+ ? insets.isVisible(WindowInsetsCompat.Type.navigationBars()) && (visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
42
+ : (visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
43
+ return new SystemBarsControllerState(behavior, statusVisible, navigationVisible);
44
+ }
45
+
46
+ void applyTo(Window window) {
47
+ if (window == null) {
48
+ return;
49
+ }
50
+
51
+ WindowInsetsControllerCompat controller = new WindowInsetsControllerCompat(window, window.getDecorView());
52
+ if (statusVisible) {
53
+ controller.show(WindowInsetsCompat.Type.statusBars());
54
+ } else {
55
+ controller.hide(WindowInsetsCompat.Type.statusBars());
56
+ }
57
+ if (navigationVisible) {
58
+ controller.show(WindowInsetsCompat.Type.navigationBars());
59
+ } else {
60
+ controller.hide(WindowInsetsCompat.Type.navigationBars());
61
+ }
62
+ controller.setSystemBarsBehavior(behavior);
63
+ }
64
+
65
+ int getBehavior() {
66
+ return behavior;
67
+ }
68
+
69
+ boolean isStatusVisible() {
70
+ return statusVisible;
71
+ }
72
+
73
+ boolean isNavigationVisible() {
74
+ return navigationVisible;
75
+ }
76
+ }
@@ -458,11 +458,75 @@ public class WebViewDialog extends ComponentDialog implements ProxyResponseRouti
458
458
  }
459
459
  fullscreenContentBehavior = null;
460
460
  baseline.restore();
461
+ syncDialogSystemBarsFromHost();
461
462
  reapplyInsetsFromWindowRoot();
462
463
  }
463
464
  if (fullscreenChangeListener != null) fullscreenChangeListener.accept(enabled);
464
465
  }
465
466
 
467
+ private void syncDialogSystemBarsFromHost() {
468
+ if (isFullscreen()) {
469
+ return;
470
+ }
471
+
472
+ if (activity == null) {
473
+ return;
474
+ }
475
+
476
+ Window hostWindow = activity.getWindow();
477
+ Window dialogWindow = getWindow();
478
+ if (hostWindow == null || dialogWindow == null) {
479
+ return;
480
+ }
481
+
482
+ if (customFullscreenView != null && customFullscreenWindow == dialogWindow) {
483
+ return;
484
+ }
485
+
486
+ SystemBarsControllerState hostState = SystemBarsControllerState.capture(hostWindow);
487
+ hostState.applyTo(dialogWindow);
488
+ applyStatusBarColorViewForHostVisibility(hostState.isStatusVisible());
489
+ }
490
+
491
+ private void applyStatusBarColorViewForHostVisibility(boolean statusBarVisible) {
492
+ if (_options != null && TextUtils.equals(_options.getToolbarType(), "blank")) {
493
+ return;
494
+ }
495
+
496
+ View statusBarColorView = findViewById(R.id.status_bar_color_view);
497
+ if (statusBarColorView == null) {
498
+ return;
499
+ }
500
+
501
+ ViewGroup.LayoutParams params = statusBarColorView.getLayoutParams();
502
+ if (!statusBarVisible) {
503
+ statusBarColorView.setVisibility(View.GONE);
504
+ if (params != null) {
505
+ params.height = 0;
506
+ statusBarColorView.setLayoutParams(params);
507
+ }
508
+ return;
509
+ }
510
+
511
+ statusBarColorView.setVisibility(View.VISIBLE);
512
+ if (params != null) {
513
+ params.height = getSystemStatusBarHeight();
514
+ statusBarColorView.setLayoutParams(params);
515
+ statusBarColorView.requestLayout();
516
+ }
517
+ }
518
+
519
+ private boolean isHostStatusBarVisible() {
520
+ if (activity == null) {
521
+ return true;
522
+ }
523
+ Window hostWindow = activity.getWindow();
524
+ if (hostWindow == null) {
525
+ return true;
526
+ }
527
+ return SystemBarsControllerState.capture(hostWindow).isStatusVisible();
528
+ }
529
+
466
530
  private void updateFullscreenExitInsets(WindowInsetsCompat insets) {
467
531
  if (fullscreenExitButton == null || insets == null) return;
468
532
  // Hidden status bars need no space in landscape; cutouts and navigation gestures always do.
@@ -630,6 +694,7 @@ public class WebViewDialog extends ComponentDialog implements ProxyResponseRouti
630
694
  @Override
631
695
  protected void onStart() {
632
696
  super.onStart();
697
+ syncDialogSystemBarsFromHost();
633
698
  applyStartupFullscreen();
634
699
  // ComponentDialog registers its own back callback in onCreate; re-add ours last so
635
700
  // handleBrowserBackNavigation runs before the built-in cancel callback (LIFO order).
@@ -2398,6 +2463,11 @@ public class WebViewDialog extends ComponentDialog implements ProxyResponseRouti
2398
2463
 
2399
2464
  // Set the height of the status bar color view
2400
2465
  if (statusBarColorView != null) {
2466
+ if (!isHostStatusBarVisible()) {
2467
+ applyStatusBarColorViewForHostVisibility(false);
2468
+ return;
2469
+ }
2470
+
2401
2471
  statusBarColorView.getLayoutParams().height = statusBarHeight;
2402
2472
  statusBarColorView.requestLayout();
2403
2473
 
@@ -2501,7 +2571,7 @@ public class WebViewDialog extends ComponentDialog implements ProxyResponseRouti
2501
2571
  }
2502
2572
 
2503
2573
  // Set web view background color
2504
- int backgroundColor = _options.getBackgroundColor().equals("white") ? Color.WHITE : Color.BLACK;
2574
+ int backgroundColor = TextUtils.equals(_options.getBackgroundColor(), "white") ? Color.WHITE : Color.BLACK;
2505
2575
  _webView.setBackgroundColor(backgroundColor);
2506
2576
 
2507
2577
  // Set text zoom if specified in options
@@ -3554,6 +3624,7 @@ public class WebViewDialog extends ComponentDialog implements ProxyResponseRouti
3554
3624
  statusBarColor,
3555
3625
  lightStatusBars
3556
3626
  );
3627
+ decorView.post(this::syncDialogSystemBarsFromHost);
3557
3628
  }
3558
3629
 
3559
3630
  requestSafeAreaInsets();
@@ -3743,6 +3814,11 @@ public class WebViewDialog extends ComponentDialog implements ProxyResponseRouti
3743
3814
  return;
3744
3815
  }
3745
3816
 
3817
+ if (!isHostStatusBarVisible()) {
3818
+ applyStatusBarColorViewForHostVisibility(false);
3819
+ return;
3820
+ }
3821
+
3746
3822
  params.height = statusBarHeight;
3747
3823
  statusBarColorView.setLayoutParams(params);
3748
3824
  statusBarColorView.requestLayout();
@@ -3776,18 +3852,24 @@ public class WebViewDialog extends ComponentDialog implements ProxyResponseRouti
3776
3852
  }
3777
3853
 
3778
3854
  int statusBarHeight = getSystemStatusBarHeight();
3855
+ boolean hostStatusBarVisible = isHostStatusBarVisible();
3779
3856
 
3780
3857
  if (statusBarColorView != null) {
3781
- ViewGroup.LayoutParams params = statusBarColorView.getLayoutParams();
3782
- if (params != null) {
3783
- params.height = statusBarHeight;
3784
- statusBarColorView.setLayoutParams(params);
3858
+ if (!hostStatusBarVisible) {
3859
+ applyStatusBarColorViewForHostVisibility(false);
3860
+ } else {
3861
+ ViewGroup.LayoutParams params = statusBarColorView.getLayoutParams();
3862
+ if (params != null) {
3863
+ params.height = statusBarHeight;
3864
+ statusBarColorView.setLayoutParams(params);
3865
+ }
3866
+ statusBarColorView.setBackgroundColor(finalBgColor);
3867
+ statusBarColorView.setVisibility(View.VISIBLE);
3785
3868
  }
3786
- statusBarColorView.setBackgroundColor(finalBgColor);
3787
- statusBarColorView.setVisibility(View.VISIBLE);
3788
3869
  }
3789
3870
 
3790
- applyAppBarTopInset(appBarLayout, appBarHandlesTopInset(toolbarView) ? statusBarHeight : 0);
3871
+ int appBarTopInset = appBarHandlesTopInset(toolbarView) && hostStatusBarVisible ? statusBarHeight : 0;
3872
+ applyAppBarTopInset(appBarLayout, appBarTopInset);
3791
3873
  appBarLayout.setBackgroundColor(finalBgColor);
3792
3874
 
3793
3875
  Window window = getWindow();
@@ -3973,12 +4055,13 @@ public class WebViewDialog extends ComponentDialog implements ProxyResponseRouti
3973
4055
  isEdgeToEdge,
3974
4056
  layoutBehindNavigationBar
3975
4057
  );
4058
+ boolean hostStatusBarVisible = isHostStatusBarVisible();
3976
4059
  int statusBarTop = SafeAreaInsetsSupport.resolveStatusBarTop(
3977
4060
  bars.top,
3978
4061
  bars.bottom,
3979
4062
  bars.left,
3980
4063
  bars.right,
3981
- getSystemStatusBarHeight()
4064
+ hostStatusBarVisible ? getSystemStatusBarHeight() : 0
3982
4065
  );
3983
4066
  int fallbackBottomInset = applyBottomInset ? getSystemNavigationBarHeight() : 0;
3984
4067
  int safeBottomInset = SafeAreaInsetsSupport.resolveSafeBottomInsetWithFallback(
@@ -4014,7 +4097,8 @@ public class WebViewDialog extends ComponentDialog implements ProxyResponseRouti
4014
4097
  // instead of the status_bar_height resource used for the initial layout.
4015
4098
  View toolbarView = findBrowserContentDescendant(R.id.tool_bar);
4016
4099
  if (toolbarView != null && toolbarView.getParent() instanceof com.google.android.material.appbar.AppBarLayout appBarLayout) {
4017
- applyAppBarTopInset(appBarLayout, statusBarTop);
4100
+ int appBarTopInset = hostStatusBarVisible ? statusBarTop : 0;
4101
+ applyAppBarTopInset(appBarLayout, appBarTopInset);
4018
4102
  }
4019
4103
  }
4020
4104
 
@@ -446,7 +446,7 @@ public class CapgoInAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
446
446
  case aware = "AWARE"
447
447
  case fakeVisible = "FAKE_VISIBLE"
448
448
  }
449
- private let pluginVersion: String = "8.22.1"
449
+ private let pluginVersion: String = "8.22.3"
450
450
  public let identifier = "CapgoInAppBrowserPlugin"
451
451
  public let jsName = "CapgoInAppBrowser"
452
452
  public let pluginMethods: [CAPPluginMethod] = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-inappbrowser",
3
- "version": "8.22.1",
3
+ "version": "8.22.3",
4
4
  "description": "Capacitor plugin in app browser",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",