From 880ab7ef03814945a6fa13585ee5502f6788fc45 Mon Sep 17 00:00:00 2001 From: Alexander Capehart Date: Thu, 2 Apr 2026 20:21:59 -0600 Subject: [PATCH] ui: another attempt at bottom sheet edge bug !!! proposal from gpt 5.4 pro !!! will revert if it doesnt work --- .../auxio/ui/BottomSheetContentBehavior.kt | 73 ++++++++++--------- 1 file changed, 39 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/org/oxycblt/auxio/ui/BottomSheetContentBehavior.kt b/app/src/main/java/org/oxycblt/auxio/ui/BottomSheetContentBehavior.kt index aed8ea316..b615bfabe 100644 --- a/app/src/main/java/org/oxycblt/auxio/ui/BottomSheetContentBehavior.kt +++ b/app/src/main/java/org/oxycblt/auxio/ui/BottomSheetContentBehavior.kt @@ -28,7 +28,6 @@ import kotlin.math.abs import org.oxycblt.auxio.util.coordinatorLayoutBehavior import org.oxycblt.auxio.util.replaceSystemBarInsetsCompat import org.oxycblt.auxio.util.systemBarInsetsCompat -import timber.log.Timber as L /** * A behavior that automatically re-layouts and re-insets content to align with the parent layout's @@ -53,6 +52,38 @@ class BottomSheetContentBehavior(context: Context, attributeSet: Attri return false } + override fun onLayoutChild(parent: CoordinatorLayout, child: V, layoutDirection: Int): Boolean { + super.onLayoutChild(parent, child, layoutDirection) + layoutContent(child) + + if (!setup) { + child.setOnApplyWindowInsetsListener { _, insets -> + lastInsets = insets + + val dep = dep ?: return@setOnApplyWindowInsetsListener insets + val behavior = dep.coordinatorLayoutBehavior as BackportBottomSheetBehavior + val consumed = behavior.calculateConsumedByBar() + if (consumed == Int.MIN_VALUE) { + return@setOnApplyWindowInsetsListener insets + } + + val bars = insets.systemBarInsetsCompat + insets.replaceSystemBarInsetsCompat( + bars.left, + bars.top, + bars.right, + consumed.coerceAtLeast(bars.bottom), + ) + } + + setup = true + } + + // Critical: seed / refresh inset dispatch after listener installation. + child.requestApplyInsets() + return true + } + override fun onDependentViewChanged( parent: CoordinatorLayout, child: V, @@ -61,14 +92,18 @@ class BottomSheetContentBehavior(context: Context, attributeSet: Attri val behavior = dependency.coordinatorLayoutBehavior as BackportBottomSheetBehavior val consumed = behavior.calculateConsumedByBar() if (consumed == Int.MIN_VALUE) { - L.d("Not laid out yet, cannot update dependent view") return false } if (consumed != lastConsumed) { - L.d("Consumed amount changed, re-applying insets") lastConsumed = consumed - lastInsets?.let(child::dispatchApplyWindowInsets) + + if (lastInsets != null) { + child.dispatchApplyWindowInsets(lastInsets) + } else { + child.requestApplyInsets() + } + measureContent(parent, child) layoutContent(child) return true @@ -89,36 +124,6 @@ class BottomSheetContentBehavior(context: Context, attributeSet: Attri return true } - override fun onLayoutChild(parent: CoordinatorLayout, child: V, layoutDirection: Int): Boolean { - super.onLayoutChild(parent, child, layoutDirection) - layoutContent(child) - - if (!setup) { - child.setOnApplyWindowInsetsListener { _, insets -> - lastInsets = insets - val dep = dep ?: return@setOnApplyWindowInsetsListener insets - val behavior = dep.coordinatorLayoutBehavior as BackportBottomSheetBehavior - val consumed = behavior.calculateConsumedByBar() - if (consumed == Int.MIN_VALUE) { - return@setOnApplyWindowInsetsListener insets - } - - val bars = insets.systemBarInsetsCompat - - insets.replaceSystemBarInsetsCompat( - bars.left, - bars.top, - bars.right, - consumed.coerceAtLeast(bars.bottom), - ) - } - - setup = true - } - - return true - } - private fun measureContent(parent: View, child: View) { val contentWidthSpec = View.MeasureSpec.makeMeasureSpec(parent.measuredWidth, View.MeasureSpec.EXACTLY)