diff --git a/.changeset/ten-bees-perform.md b/.changeset/ten-bees-perform.md new file mode 100644 index 00000000..042fb724 --- /dev/null +++ b/.changeset/ten-bees-perform.md @@ -0,0 +1,5 @@ +--- +'@capawesome/capacitor-android-edge-to-edge-support': patch +--- + +fix: resize webview when keyboard is shown diff --git a/packages/android-edge-to-edge-support/android/src/main/java/io/capawesome/capacitorjs/plugins/androidedgetoedgesupport/EdgeToEdge.java b/packages/android-edge-to-edge-support/android/src/main/java/io/capawesome/capacitorjs/plugins/androidedgetoedgesupport/EdgeToEdge.java index 2fd29da3..83a02261 100644 --- a/packages/android-edge-to-edge-support/android/src/main/java/io/capawesome/capacitorjs/plugins/androidedgetoedgesupport/EdgeToEdge.java +++ b/packages/android-edge-to-edge-support/android/src/main/java/io/capawesome/capacitorjs/plugins/androidedgetoedgesupport/EdgeToEdge.java @@ -46,25 +46,24 @@ private void applyInsets() { parent.setBackgroundColor(this.config.getBackgroundColor()); // Apply insets to disable the edge-to-edge feature ViewCompat.setOnApplyWindowInsetsListener(view, (v, windowInsets) -> { - Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()); - Boolean keyboardVisible = windowInsets.isVisible(WindowInsetsCompat.Type.ime()); + // Retrieve system bars insets (for status/navigation bars) + Insets systemBarsInsets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()); + // Retrieve keyboard (IME) insets + Insets imeInsets = windowInsets.getInsets(WindowInsetsCompat.Type.ime()); + boolean keyboardVisible = windowInsets.isVisible(WindowInsetsCompat.Type.ime()); ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) v.getLayoutParams(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) { - if (keyboardVisible) { - mlp.bottomMargin = 0; - } else { - mlp.bottomMargin = insets.bottom; - } - } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { - mlp.bottomMargin = insets.bottom; - } + // Apply the appropriate bottom inset: use keyboard inset if visible, else system bars inset + mlp.bottomMargin = keyboardVisible ? imeInsets.bottom : systemBarsInsets.bottom; + + // Set the other margins using system bars insets + mlp.topMargin = systemBarsInsets.top; + mlp.leftMargin = systemBarsInsets.left; + mlp.rightMargin = systemBarsInsets.right; - mlp.leftMargin = insets.left; - mlp.rightMargin = insets.right; - mlp.topMargin = insets.top; v.setLayoutParams(mlp); + return WindowInsetsCompat.CONSUMED; }); }