Skip to content

Commit 880ab7e

Browse files
committed
ui: another attempt at bottom sheet edge bug
!!! proposal from gpt 5.4 pro !!! will revert if it doesnt work
1 parent 801c14c commit 880ab7e

1 file changed

Lines changed: 39 additions & 34 deletions

File tree

app/src/main/java/org/oxycblt/auxio/ui/BottomSheetContentBehavior.kt

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import kotlin.math.abs
2828
import org.oxycblt.auxio.util.coordinatorLayoutBehavior
2929
import org.oxycblt.auxio.util.replaceSystemBarInsetsCompat
3030
import org.oxycblt.auxio.util.systemBarInsetsCompat
31-
import timber.log.Timber as L
3231

3332
/**
3433
* 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
5352
return false
5453
}
5554

55+
override fun onLayoutChild(parent: CoordinatorLayout, child: V, layoutDirection: Int): Boolean {
56+
super.onLayoutChild(parent, child, layoutDirection)
57+
layoutContent(child)
58+
59+
if (!setup) {
60+
child.setOnApplyWindowInsetsListener { _, insets ->
61+
lastInsets = insets
62+
63+
val dep = dep ?: return@setOnApplyWindowInsetsListener insets
64+
val behavior = dep.coordinatorLayoutBehavior as BackportBottomSheetBehavior
65+
val consumed = behavior.calculateConsumedByBar()
66+
if (consumed == Int.MIN_VALUE) {
67+
return@setOnApplyWindowInsetsListener insets
68+
}
69+
70+
val bars = insets.systemBarInsetsCompat
71+
insets.replaceSystemBarInsetsCompat(
72+
bars.left,
73+
bars.top,
74+
bars.right,
75+
consumed.coerceAtLeast(bars.bottom),
76+
)
77+
}
78+
79+
setup = true
80+
}
81+
82+
// Critical: seed / refresh inset dispatch after listener installation.
83+
child.requestApplyInsets()
84+
return true
85+
}
86+
5687
override fun onDependentViewChanged(
5788
parent: CoordinatorLayout,
5889
child: V,
@@ -61,14 +92,18 @@ class BottomSheetContentBehavior<V : View>(context: Context, attributeSet: Attri
6192
val behavior = dependency.coordinatorLayoutBehavior as BackportBottomSheetBehavior
6293
val consumed = behavior.calculateConsumedByBar()
6394
if (consumed == Int.MIN_VALUE) {
64-
L.d("Not laid out yet, cannot update dependent view")
6595
return false
6696
}
6797

6898
if (consumed != lastConsumed) {
69-
L.d("Consumed amount changed, re-applying insets")
7099
lastConsumed = consumed
71-
lastInsets?.let(child::dispatchApplyWindowInsets)
100+
101+
if (lastInsets != null) {
102+
child.dispatchApplyWindowInsets(lastInsets)
103+
} else {
104+
child.requestApplyInsets()
105+
}
106+
72107
measureContent(parent, child)
73108
layoutContent(child)
74109
return true
@@ -89,36 +124,6 @@ class BottomSheetContentBehavior<V : View>(context: Context, attributeSet: Attri
89124
return true
90125
}
91126

92-
override fun onLayoutChild(parent: CoordinatorLayout, child: V, layoutDirection: Int): Boolean {
93-
super.onLayoutChild(parent, child, layoutDirection)
94-
layoutContent(child)
95-
96-
if (!setup) {
97-
child.setOnApplyWindowInsetsListener { _, insets ->
98-
lastInsets = insets
99-
val dep = dep ?: return@setOnApplyWindowInsetsListener insets
100-
val behavior = dep.coordinatorLayoutBehavior as BackportBottomSheetBehavior
101-
val consumed = behavior.calculateConsumedByBar()
102-
if (consumed == Int.MIN_VALUE) {
103-
return@setOnApplyWindowInsetsListener insets
104-
}
105-
106-
val bars = insets.systemBarInsetsCompat
107-
108-
insets.replaceSystemBarInsetsCompat(
109-
bars.left,
110-
bars.top,
111-
bars.right,
112-
consumed.coerceAtLeast(bars.bottom),
113-
)
114-
}
115-
116-
setup = true
117-
}
118-
119-
return true
120-
}
121-
122127
private fun measureContent(parent: View, child: View) {
123128
val contentWidthSpec =
124129
View.MeasureSpec.makeMeasureSpec(parent.measuredWidth, View.MeasureSpec.EXACTLY)

0 commit comments

Comments
 (0)