fix(SystemBars): keep the system bar backgrounds and navigation bar scrim
Description
Since #8535, SystemBars sets its window insets listener on the DecorView. A listener is called instead of the view's own onApplyWindowInsets, and DecorView#onApplyWindowInsets is where the framework lays out the system bar backgrounds, including the contrast scrim behind the 3-button navigation bar. The scrim is therefore never drawn:
- Android 15+, default template: no scrim.
- Android 14 and older with
EdgeToEdge.enable(this)(as the SystemBars docs recommend): no scrim. - Android 14 and older without edge-to-edge: the navigation bar loses its opaque background as well.
This PR makes three changes in initWindowInsetsListener():
- The listener calls the DecorView's own
onApplyWindowInsetsfirst, as theView.OnApplyWindowInsetsListenerdocs describe, and continues with the insets it returns. On windows that are not edge-to-edge, the DecorView reserves the navigation bar area for its background and consumes that inset; using its result keeps that area from being padded twice. On edge-to-edge windows it consumes nothing, so the insets are the same as before. - The padding goes on the WebView's parent instead of the DecorView, as it did before #8535. The DecorView is the
FrameLayoutthat holds the system bar background views, so padding it would move them into the content, for example a scrim band above the keyboard or above the navigation bar. - If the WebView is not attached to a parent (for example a Fragment-hosted bridge whose view was destroyed), the listener returns the insets unchanged instead of padding a null view.
Change Type
- Fix
- Feature
- Refactor
- Breaking Change
- Documentation
- Other (CI, chores, etc.)
Rationale / Problems Fixed
Fixes #8724
Tests or Reproductions
Repro: https://github.com/adrenaline15/capacitor-systembars-scrim-repro. It is the default template with a page of alternating dark and light rows that prints env(safe-area-inset-*), --safe-area-inset-* and innerHeight. Buttons switch between viewport-fit=cover (insets passed through) and no cover (SystemBars pads the native view), and an input opens the keyboard. apply-fix.sh applies this PR to @capacitor/android 8.6.2.
Emulators with 3-button navigation: Android 16 (API 36, WebView 156) and Android 14 (API 34, WebView 157, also in landscape). Each was tested with and without EdgeToEdge.enable, with cover, without cover, and with the keyboard open.
| Setup | 8.5.1 | 8.6.2 | 8.6.2 + this PR |
|---|---|---|---|
| API 36, default template | scrim | no scrim | scrim |
API 36, EdgeToEdge.enable | scrim | no scrim | scrim |
API 34, EdgeToEdge.enable | scrim | no scrim | scrim |
| API 34, default template | black navigation bar | light grey bar | black navigation bar |
- API 36: every case is pixel-identical to 8.5.1 below the status bar, apart from the blinking text cursor.
- API 34: the navigation bar matches 8.5.1 in every case, and the WebView keeps the size and position it has on 8.6.2, in portrait and landscape.
env(safe-area-inset-*),--safe-area-inset-*andinnerHeightare the same as on 8.6.2.
npm run verify in android/ passes, and prettier reports no changes.
Screenshots / Media
"1st commit" is the first commit of this PR on its own, before the padding moved to the WebView's parent.
Platforms Affected
- Android
- iOS
- Web
Notes / Comments
- The same code is on
8.x, and both commits cherry-pick onto it cleanly. - Not tested below API 34.
- On API 34 without edge-to-edge,
--safe-area-inset-topis still49pxalthough the window starts below the status bar (#8623). This PR does not change that.