@capgo/capacitor-native-navigation 8.4.4 → 8.4.5

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.
@@ -112,7 +112,10 @@ public class NativeNavigationPlugin extends Plugin {
112
112
  public void load() {
113
113
  Activity activity = getActivity();
114
114
  if (activity != null) {
115
- activity.runOnUiThread(this::enableEdgeToEdge);
115
+ activity.runOnUiThread(() -> {
116
+ enableEdgeToEdge();
117
+ watchContentRootBounds();
118
+ });
116
119
  }
117
120
  }
118
121
 
@@ -2062,7 +2065,21 @@ public class NativeNavigationPlugin extends Plugin {
2062
2065
  }
2063
2066
  }
2064
2067
 
2068
+ /**
2069
+ * The chrome is laid out inside {@code android.R.id.content}, so it only needs to clear the part of a
2070
+ * system bar that actually overlaps that view. Capacitor's SystemBars plugin (default
2071
+ * {@code insetsHandling: 'css'} without {@code viewport-fit=cover}) pads the decor view by the system bars,
2072
+ * which already moves the content root clear of them; adding the full inset again doubled the gap.
2073
+ */
2065
2074
  private int statusBarInset() {
2075
+ return Math.max(0, rawStatusBarInset() - contentRootTopOffset());
2076
+ }
2077
+
2078
+ private int navigationBarInset() {
2079
+ return Math.max(0, rawNavigationBarInset() - contentRootBottomOffset());
2080
+ }
2081
+
2082
+ private int rawStatusBarInset() {
2066
2083
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
2067
2084
  WindowInsets insets = getActivity().getWindow().getDecorView().getRootWindowInsets();
2068
2085
  if (insets != null) {
@@ -2072,7 +2089,7 @@ public class NativeNavigationPlugin extends Plugin {
2072
2089
  return systemDimension("status_bar_height");
2073
2090
  }
2074
2091
 
2075
- private int navigationBarInset() {
2092
+ private int rawNavigationBarInset() {
2076
2093
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
2077
2094
  WindowInsets insets = getActivity().getWindow().getDecorView().getRootWindowInsets();
2078
2095
  if (insets != null) {
@@ -2082,6 +2099,45 @@ public class NativeNavigationPlugin extends Plugin {
2082
2099
  return systemDimension("navigation_bar_height");
2083
2100
  }
2084
2101
 
2102
+ private int contentRootTopOffset() {
2103
+ FrameLayout root = contentRoot();
2104
+ if (root == null || !root.isLaidOut()) {
2105
+ return 0;
2106
+ }
2107
+ int[] location = new int[2];
2108
+ root.getLocationInWindow(location);
2109
+ return Math.max(0, location[1]);
2110
+ }
2111
+
2112
+ private int contentRootBottomOffset() {
2113
+ FrameLayout root = contentRoot();
2114
+ Activity activity = getActivity();
2115
+ if (root == null || activity == null || !root.isLaidOut()) {
2116
+ return 0;
2117
+ }
2118
+ View decor = activity.getWindow().getDecorView();
2119
+ int[] location = new int[2];
2120
+ root.getLocationInWindow(location);
2121
+ return Math.max(0, decor.getHeight() - (location[1] + root.getHeight()));
2122
+ }
2123
+
2124
+ private void watchContentRootBounds() {
2125
+ FrameLayout root = contentRoot();
2126
+ if (root == null) {
2127
+ return;
2128
+ }
2129
+ // SystemBars can add or drop its decor padding after load (for example once viewport-fit=cover is
2130
+ // detected), which moves the content root without a call into this plugin. Re-run layout when it moves.
2131
+ root.addOnLayoutChangeListener((view, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
2132
+ if (top == oldTop && bottom == oldBottom && left == oldLeft && right == oldRight) {
2133
+ return;
2134
+ }
2135
+ if (navbarVisible || tabbarVisible) {
2136
+ view.post(this::updateInsetsAndNotify);
2137
+ }
2138
+ });
2139
+ }
2140
+
2085
2141
  private int systemDimension(String name) {
2086
2142
  int id = getContext().getResources().getIdentifier(name, "dimen", "android");
2087
2143
  return id == 0 ? 0 : getContext().getResources().getDimensionPixelSize(id);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-native-navigation",
3
- "version": "8.4.4",
3
+ "version": "8.4.5",
4
4
  "description": "Capacitor plugin for native navbar, tabbar, safe-area handling, and WebView snapshot transitions.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",