From dcecec4d6fce3379272eb53401ab577521fd372d Mon Sep 17 00:00:00 2001 From: Markus Fisch Date: Wed, 10 Jun 2026 21:19:44 +0200 Subject: [PATCH] Make window inset application idempotent The inset listener applied the status bar padding only once, guarded by a paddingTop == 0 check, and grew the toolbar height incrementally. When the first callback reported wrong insets the layout stayed stuck with stale values, so affected devices only settled after several rotations. Recompute the padded toolbar height from a captured bare height on every callback and always set the nav bar padding, including back to zero, so the layout converges on the first correct inset pass. --- .../android/binaryeye/view/WindowInsets.kt | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/app/src/main/kotlin/de/markusfisch/android/binaryeye/view/WindowInsets.kt b/app/src/main/kotlin/de/markusfisch/android/binaryeye/view/WindowInsets.kt index fd835669..e4b865ef 100644 --- a/app/src/main/kotlin/de/markusfisch/android/binaryeye/view/WindowInsets.kt +++ b/app/src/main/kotlin/de/markusfisch/android/binaryeye/view/WindowInsets.kt @@ -20,23 +20,25 @@ fun setPaddingFromWindowInsets( if (Build.VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM) { return } + // Capture the bare toolbar height so the listener can recompute the + // padded height from scratch every time. Applying the insets only + // once (or adding them incrementally) leaves the layout stuck with + // stale values when the first callback reports wrong insets, which + // is why some devices only settled after several rotations. + val baseToolbarHeight = toolbarHeight mainLayout.setOnApplyWindowInsetsListener { _, insets -> val systemBarInsets = insets.getInsets( WindowInsets.Type.systemBars() ) val statusBarTop = systemBarInsets.top - if (toolbar.paddingTop == 0 && statusBarTop > 0) { - toolbar.setPadding(0, statusBarTop, 0, 0) - toolbar.layoutParams.height += statusBarTop - } + toolbar.setPadding(0, statusBarTop, 0, 0) + toolbar.layoutParams.height = baseToolbarHeight + statusBarTop val navBarBottom = systemBarInsets.bottom - if (navBarBottom > 0) { - mainLayout.setPadding(0, 0, 0, navBarBottom); - navbar?.apply { - layoutParams.height = navBarBottom - } + mainLayout.setPadding(0, 0, 0, navBarBottom) + navbar?.apply { + layoutParams.height = navBarBottom } insets