Fix scrollbar crash when container is shorter than min thumb height

coerceIn(10dp..height) throws IllegalArgumentException when the drawn
height is below 10dp (e.g. 0 during a sheet animation). Skip drawing at
zero height and cap the minimum thumb height at the container height.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CSFYvnepFMHdUqYc3SzXVC
This commit is contained in:
Claude
2026-10-03 13:50:23 +00:00
parent fc2e0de5dd
commit d5f31c5c39
@@ -18,13 +18,13 @@ fun Modifier.verticalScrollbar(
Modifier.drawWithContent {
drawContent()
if (state.maxValue > 0) {
val height = size.height
if (state.maxValue > 0 && height > 0f) {
val width = size.width
val height = size.height
val scrollFraction = state.value.toFloat() / state.maxValue.toFloat()
val scrollbarHeight = (height * height / (state.maxValue + height))
.coerceIn(10.dp.toPx()..height)
.coerceIn(10.dp.toPx().coerceAtMost(height)..height)
val scrollableHeight = height - scrollbarHeight
val scrollbarY = scrollableHeight * scrollFraction