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:
@@ -28,7 +28,6 @@ import kotlin.math.abs
|
|||||||
import org.oxycblt.auxio.util.coordinatorLayoutBehavior
|
import org.oxycblt.auxio.util.coordinatorLayoutBehavior
|
||||||
import org.oxycblt.auxio.util.replaceSystemBarInsetsCompat
|
import org.oxycblt.auxio.util.replaceSystemBarInsetsCompat
|
||||||
import org.oxycblt.auxio.util.systemBarInsetsCompat
|
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
|
* 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
|
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(
|
override fun onDependentViewChanged(
|
||||||
parent: CoordinatorLayout,
|
parent: CoordinatorLayout,
|
||||||
child: V,
|
child: V,
|
||||||
@@ -61,14 +92,18 @@ class BottomSheetContentBehavior<V : View>(context: Context, attributeSet: Attri
|
|||||||
val behavior = dependency.coordinatorLayoutBehavior as BackportBottomSheetBehavior
|
val behavior = dependency.coordinatorLayoutBehavior as BackportBottomSheetBehavior
|
||||||
val consumed = behavior.calculateConsumedByBar()
|
val consumed = behavior.calculateConsumedByBar()
|
||||||
if (consumed == Int.MIN_VALUE) {
|
if (consumed == Int.MIN_VALUE) {
|
||||||
L.d("Not laid out yet, cannot update dependent view")
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if (consumed != lastConsumed) {
|
if (consumed != lastConsumed) {
|
||||||
L.d("Consumed amount changed, re-applying insets")
|
|
||||||
lastConsumed = consumed
|
lastConsumed = consumed
|
||||||
lastInsets?.let(child::dispatchApplyWindowInsets)
|
|
||||||
|
if (lastInsets != null) {
|
||||||
|
child.dispatchApplyWindowInsets(lastInsets)
|
||||||
|
} else {
|
||||||
|
child.requestApplyInsets()
|
||||||
|
}
|
||||||
|
|
||||||
measureContent(parent, child)
|
measureContent(parent, child)
|
||||||
layoutContent(child)
|
layoutContent(child)
|
||||||
return true
|
return true
|
||||||
@@ -89,36 +124,6 @@ class BottomSheetContentBehavior<V : View>(context: Context, attributeSet: Attri
|
|||||||
return true
|
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) {
|
private fun measureContent(parent: View, child: View) {
|
||||||
val contentWidthSpec =
|
val contentWidthSpec =
|
||||||
View.MeasureSpec.makeMeasureSpec(parent.measuredWidth, View.MeasureSpec.EXACTLY)
|
View.MeasureSpec.makeMeasureSpec(parent.measuredWidth, View.MeasureSpec.EXACTLY)
|
||||||
|
|||||||
Reference in New Issue
Block a user