Skip to content

Commit 2975b96

Browse files
authored
fix(android)!: Adding keyboard insets handling (#8236)
1 parent b30c472 commit 2975b96

File tree

3 files changed

+12
-20
lines changed

3 files changed

+12
-20
lines changed

android/capacitor/src/main/java/com/getcapacitor/CapConfig.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ public class CapConfig {
5454
private String errorPath;
5555
private boolean zoomableWebView = false;
5656
private boolean resolveServiceWorkerRequests = true;
57-
private String adjustMarginsForEdgeToEdge = "auto";
5857

5958
// Embedded
6059
private String startPath;
@@ -182,7 +181,6 @@ private CapConfig(Builder builder) {
182181
this.errorPath = builder.errorPath;
183182
this.zoomableWebView = builder.zoomableWebView;
184183
this.resolveServiceWorkerRequests = builder.resolveServiceWorkerRequests;
185-
this.adjustMarginsForEdgeToEdge = builder.adjustMarginsForEdgeToEdge;
186184

187185
// Embedded
188186
this.startPath = builder.startPath;
@@ -288,7 +286,6 @@ private void deserializeConfig(@Nullable Context context) {
288286
webContentsDebuggingEnabled = JSONUtils.getBoolean(configJSON, "android.webContentsDebuggingEnabled", isDebug);
289287
zoomableWebView = JSONUtils.getBoolean(configJSON, "android.zoomEnabled", JSONUtils.getBoolean(configJSON, "zoomEnabled", false));
290288
resolveServiceWorkerRequests = JSONUtils.getBoolean(configJSON, "android.resolveServiceWorkerRequests", true);
291-
adjustMarginsForEdgeToEdge = JSONUtils.getString(configJSON, "android.adjustMarginsForEdgeToEdge", "auto");
292289

293290
String logBehavior = JSONUtils.getString(
294291
configJSON,
@@ -405,10 +402,6 @@ public boolean isUsingLegacyBridge() {
405402
return useLegacyBridge;
406403
}
407404

408-
public String adjustMarginsForEdgeToEdge() {
409-
return adjustMarginsForEdgeToEdge;
410-
}
411-
412405
public int getMinWebViewVersion() {
413406
if (minWebViewVersion < MINIMUM_ANDROID_WEBVIEW_VERSION) {
414407
Logger.warn("Specified minimum webview version is too low, defaulting to " + MINIMUM_ANDROID_WEBVIEW_VERSION);
@@ -589,7 +582,6 @@ public static class Builder {
589582
private int minHuaweiWebViewVersion = DEFAULT_HUAWEI_WEBVIEW_VERSION;
590583
private boolean zoomableWebView = false;
591584
private boolean resolveServiceWorkerRequests = true;
592-
private String adjustMarginsForEdgeToEdge = "auto";
593585

594586
// Embedded
595587
private String startPath = null;

android/capacitor/src/main/java/com/getcapacitor/plugin/SystemBars.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,18 @@ private void setupSafeAreaInsets(boolean hasFixedWebView, boolean hasMetaViewpor
123123
}
124124

125125
Insets safeArea = insets.getInsets(WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout());
126-
injectSafeAreaCSS(safeArea.top, safeArea.right, safeArea.bottom, safeArea.left);
126+
Insets imeInsets = insets.getInsets(WindowInsetsCompat.Type.ime());
127+
boolean keyboardVisible = insets.isVisible(WindowInsetsCompat.Type.ime());
128+
129+
int bottomInsets = safeArea.bottom;
130+
131+
if (keyboardVisible) {
132+
// When https://issues.chromium.org/issues/457682720 is fixed and released,
133+
// add behind a WebView version check
134+
bottomInsets = imeInsets.bottom - bottomInsets;
135+
}
136+
137+
injectSafeAreaCSS(safeArea.top, safeArea.right, bottomInsets, safeArea.left);
127138

128139
return WindowInsetsCompat.CONSUMED;
129140
});

cli/src/declarations.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -297,17 +297,6 @@ export interface CapacitorConfig {
297297
* @default true
298298
*/
299299
resolveServiceWorkerRequests?: boolean;
300-
301-
/**
302-
* If set to "force", margins will be adjusted for edge to edge regardless of any other settings.
303-
* If set to "auto", will check for Android 15 and the setting of [windowOptOutEdgeToEdgeEnforcement](https://developer.android.com/reference/android/R.attr#windowOptOutEdgeToEdgeEnforcement) and will adjust margins if on Android 15 and windowOptOutEdgeToEdgeEnforcement is false/missing.
304-
* If set to "disable", or is missing, will not adjust margins at all.
305-
* In Capacitor 8, this default will be changed to 'auto'
306-
*
307-
* @since 7.1.0
308-
* @default disable
309-
*/
310-
adjustMarginsForEdgeToEdge?: 'auto' | 'force' | 'disable';
311300
};
312301

313302
ios?: {

0 commit comments

Comments
 (0)