Skip to content

Commit 94c8d30

Browse files
luisbytesrobingenz
andauthored
feat(android-edge-to-edge-support): add resize webview when keyboard is shown (#485)
* feat(android-edge-to-edge-support): add resize webview when keyboard is shown * Update changelog * Update .changeset/ten-bees-perform.md * chore(android-edge-to-edge-support): fmt --------- Co-authored-by: Robin Genz <mail@robingenz.dev>
1 parent 5a05e80 commit 94c8d30

2 files changed

Lines changed: 18 additions & 14 deletions

File tree

.changeset/ten-bees-perform.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@capawesome/capacitor-android-edge-to-edge-support': patch
3+
---
4+
5+
fix: resize webview when keyboard is shown

packages/android-edge-to-edge-support/android/src/main/java/io/capawesome/capacitorjs/plugins/androidedgetoedgesupport/EdgeToEdge.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,24 @@ private void applyInsets() {
4646
parent.setBackgroundColor(this.config.getBackgroundColor());
4747
// Apply insets to disable the edge-to-edge feature
4848
ViewCompat.setOnApplyWindowInsetsListener(view, (v, windowInsets) -> {
49-
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
50-
Boolean keyboardVisible = windowInsets.isVisible(WindowInsetsCompat.Type.ime());
49+
// Retrieve system bars insets (for status/navigation bars)
50+
Insets systemBarsInsets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
51+
// Retrieve keyboard (IME) insets
52+
Insets imeInsets = windowInsets.getInsets(WindowInsetsCompat.Type.ime());
53+
boolean keyboardVisible = windowInsets.isVisible(WindowInsetsCompat.Type.ime());
5154

5255
ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
5356

54-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
55-
if (keyboardVisible) {
56-
mlp.bottomMargin = 0;
57-
} else {
58-
mlp.bottomMargin = insets.bottom;
59-
}
60-
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
61-
mlp.bottomMargin = insets.bottom;
62-
}
57+
// Apply the appropriate bottom inset: use keyboard inset if visible, else system bars inset
58+
mlp.bottomMargin = keyboardVisible ? imeInsets.bottom : systemBarsInsets.bottom;
59+
60+
// Set the other margins using system bars insets
61+
mlp.topMargin = systemBarsInsets.top;
62+
mlp.leftMargin = systemBarsInsets.left;
63+
mlp.rightMargin = systemBarsInsets.right;
6364

64-
mlp.leftMargin = insets.left;
65-
mlp.rightMargin = insets.right;
66-
mlp.topMargin = insets.top;
6765
v.setLayoutParams(mlp);
66+
6867
return WindowInsetsCompat.CONSUMED;
6968
});
7069
}

0 commit comments

Comments
 (0)