Skip to content

fix(CordovaActivity): adjust dispatched window insets for WebView margins - #2022

Open
GitToTheHub wants to merge 2 commits into
masterfrom
pr-adjust-dispatched-window-insets-for-webview-margins
Open

GitToTheHub wants to merge 2 commits into
masterfrom
pr-adjust-dispatched-window-insets-for-webview-margins

Conversation

@GitToTheHub

@GitToTheHub GitToTheHub commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Platforms affected

Android

Motivation and Context

  • Cordova moved the WebView away from system bars using margins, but the WebView could still receive those same insets. Pages using env(safe-area-inset-*) could then apply extra spacing for areas the WebView no longer overlapped. See issue CSS safe-area-inset-* vars not 0 when AndroidEdgeToEdge is false #2021 for more details.
  • CordovaActivity applies system-bar, display-cutout, and IME insets to the WebView’s margins and sizes the status-bar overlay. It then now dispatches adjusted insets to child views, subtracting the margin offsets already applied so those same offsets aren’t reported again to the WebView. Insets for areas where the WebView still draws edge-to-edge remain available to it.
  • Fixes CSS safe-area-inset-* vars not 0 when AndroidEdgeToEdge is false #2021
  • Generated-By: GPT-6 Luna

Description

Testing

I tested it with AndroidEdgeToEdge setting to false and true on an Android 15 emulator.

Setting AndroidEdgeToEdge to false sets safe-area-inset-* vars to 0:

Setting AndroidEdgeToEdge to true sets the safe-area-inset-* vars to the excepted values, for e.g. safe-area-inset-top is set to 55px on portrait:

Checklist

  • I've run the tests to see all new and existing tests pass
  • I added automated test coverage as appropriate for this change
  • Commit is prefixed with (platform) if this change only applies to one platform (e.g. (android))
  • If this Pull Request resolves an issue, I linked to the issue in the text above (and used the correct keyword to close issues using keywords)
  • I've updated the documentation if necessary

- Cordova moved the WebView away from system bars using margins, but the WebView could still receive those same insets. Pages using env(safe-area-inset-*) could then apply extra spacing for areas the WebView no longer overlapped.
- `CordovaActivity` applies system-bar, display-cutout, and IME insets to the WebView’s margins and sizes the status-bar overlay. It then now dispatches adjusted insets to child views, subtracting the margin offsets already applied so those same offsets aren’t reported again to the WebView. Insets for areas where the WebView still draws edge-to-edge remain available to it.
- Fixes `safe-area-inset-*` vars not 0 when `AndroidEdgeToEdge` is `false`
- Fixes #2021
- Generated-By: GPT-6 Luna
@codecov-commenter

codecov-commenter commented Sep 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.20%. Comparing base (652e51b) to head (0ae5d2f).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2022   +/-   ##
=======================================
  Coverage   63.20%   63.20%           
=======================================
  Files          24       24           
  Lines        4922     4922           
=======================================
  Hits         3111     3111           
  Misses       1811     1811           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@GitToTheHub GitToTheHub mentioned this pull request Sep 27, 2026
15 tasks
@GitToTheHub GitToTheHub changed the title Adjust dispatched window insets for WebView margins fix(statusbar): adjust dispatched window insets for WebView margins Oct 3, 2026
@GitToTheHub GitToTheHub changed the title fix(statusbar): adjust dispatched window insets for WebView margins fix(CordovaActivity): adjust dispatched window insets for WebView margins Oct 3, 2026
@GitToTheHub

Copy link
Copy Markdown
Contributor Author

If no one has any objections, I would merge this

@scyclops

Copy link
Copy Markdown

I'm not sure why but applying this change appears to cause the software keyboard to cover up text inputs that are in the space where the keyboard will show when the text inputs are focused. Without this change, the webview automatically moves the page up so that the text input isn't covered by the keyboard. Tested on an Android 13 device with AndroidEdgeToEdge = true.

@GitToTheHub

Copy link
Copy Markdown
Contributor Author

Thanks for reporting this. I tested on Android 13 and 15 with WebView 149, plus WebView 109 on Android 13, with edge-to-edge enabled and disabled.

The current change also reduces keyboard insets, although its purpose is to correct safe-area values. I’ve prepared a narrower adjustment that preserves keyboard insets. In my tests, safe-area values remain zero with edge-to-edge disabled, and keyboard resizing, typing, and dismissal work as expected.

I haven’t reproduced your exact overlap issue with edge-to-edge enabled. Could you share your Android System WebView version and, if possible, a minimal HTML/CSS example? That would help verify whether the adjustment resolves your case.

Also you could check a minimal Hello World app with no additional plugins.

@scyclops

Copy link
Copy Markdown

After testing again, the bug disappeared when I disabled a specific 3rd party cordova plugin so the bug is probably in that plugin and it's OnApplyWindowInsetsListener (cordova-plugin-admob-nextgen).

@GitToTheHub

Copy link
Copy Markdown
Contributor Author

Thanks for testing again and narrowing it down! That would explain why I couldn’t reproduce the issue without that plugin. Its OnApplyWindowInsetsListener may interact with Cordova’s inset handling. If you open an issue with the plugin, please link it here so we can better understand the interaction with Cordova’s inset handling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CSS safe-area-inset-* vars not 0 when AndroidEdgeToEdge is false

3 participants