apache / apache/cordova-android

When using android:windowSoftInputMode="adjustResize" and env(safe-area-inset-top) in a Cordova app targeting targetSdkVersion 35, the app should behave as before

Open
#1,848 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
3.8k
Forks
1.6k
Avg merge
16h 18m
Merged PRs (30d)
11

Description

# Bug Report

## Problem

### What is expected to happen?
When using android:windowSoftInputMode="adjustResize" and env(safe-area-inset-top) in a Cordova app targeting targetSdkVersion 35, the app should behave as before:

The keyboard should resize the WebView content properly.

The env(safe-area-inset-top) variable should apply correct top padding to accommodate notches/status bar.

### What does actually happen?

When targeting SDK 35 (Android 15):

The keyboard behavior (adjustResize) no longer works correctly without applying manual WindowInsets handling.

The CSS variable env(safe-area-inset-top) returns 0px or is ignored in Android WebView, resulting in headers and content being overlapped by the status bar or notch.

A manual workaround using ViewTreeObserver and JavaScript is required to restore proper layout and safe-area behavior.

## Information

When targeting SDK 35 (Android 15):

The keyboard behavior (adjustResize) no longer works correctly without applying manual WindowInsets handling.

The CSS variable env(safe-area-inset-top) returns 0px or is ignored in Android WebView, resulting in headers and content being overlapped by the status bar or notch.

A manual workaround using ViewTreeObserver and JavaScript is required to restore proper layout and safe-area behavior.

### Command or Code

### Environment, Platform, Device

Environment: Cordova + Android

Platform: Android 15 (API 35)

Devices: Multiple (Pixel, Samsung, Xiaomi)

Emulator and physical devices tested

### Version information

### Solution
1. Add this Java class to your project: SoftInputAssist.java

This helper listens for keyboard changes and manually adjusts the layout:
```java
** Open SoftInputAssist.java **
package mi.app.cordova;

import android.app.Activity;
import android.graphics.Rect;
import android.view.View;
import android.view.ViewTreeObserver;

public class SoftInputAssist {
private final View rootView;
private final View contentView;
private int previousHeight;

public SoftInputAssist(Activity activity) {
rootView = activity.getWindow().getDecorView();
contentView = activity.findViewById(android.R.id.content);

rootView.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
Rect r = new Rect();
rootView.getWindowVisibleDisplayFrame(r);
int heightDiff = rootView.getHeight() - (r.bottom - r.top);

if (previousHeight != heightDiff) {
previousHeight = heightDiff;
contentView.setPadding(0, 0, 0, heightDiff);
}
});
}
}
** Close SoftInputAssist.java **

2. Call SoftInputAssist from MainActivity.java

Modify your MainActivity like this:
```java
** Open MainActivity.java **
package mi.app.cordova;

import android.os.Bundle;
import org.apache.cordova.*;

public class MainActivity extends CordovaActivity {
private SoftInputAssist softInputAssist;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// enable Cordova apps to be started in the background
Bundle extras = getIntent().getExtras();
if (extras != null && extras.getBoolean("cdvStartInBackground", false)) {
moveTaskToBack(true);
}

// Carga el contenido principal de Cordova
loadUrl(launchUrl);

// Inicializa el listener para el teclado
softInputAssist = new SoftInputAssist(this);
}
}
** Close MainActivity.java **
## Checklist

- [x] I searched for existing GitHub issues
- [ x] I updated all Cordova tooling to most recent version
- [ x] I included all the necessary information above

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue in a Cordova Android app targeting API 35 with the provided adjustResize activity configuration. Start by comparing the MainActivity.java and SoftInputAssist.java workaround with Cordova Android's WebView and window-insets handling. Done means the keyboard resizes the WebView and env(safe-area-inset-top) supplies correct top spacing without an app-level workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java, javascript
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.