ui: another attempt at bottom sheet edge bug

!!! proposal from gpt 5.4 pro !!!

will revert if it doesnt work
This commit is contained in:
Alexander Capehart
2026-04-02 20:22:23 -06:00
parent 801c14ce91
commit 880ab7ef03
@@ -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<V : View>(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<V : View>(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<V : View>(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)