Я пытался реализовать собственное решение, но оно работает неправильно.
Код: Выделить всё
@Composable
fun Modifier.simpleVerticalScrollbar(
state: ScrollState,
width: Dp = 8.dp
): Modifier {
val targetAlpha = if (state.isScrollInProgress) 1f else 0f
val duration = if (state.isScrollInProgress) 150 else 500
val alpha by animateFloatAsState(
targetValue = targetAlpha,
animationSpec = tween(durationMillis = duration), label = ""
)
return drawWithContent {
drawContent()
val firstVisibleElementIndex = state.viewportSize
val needDrawScrollbar = state.isScrollInProgress || alpha > 0.0f
// Draw scrollbar if scrolling or if the animation is still running and lazy column has content
if (needDrawScrollbar) {
val elementHeight = this.size.height / state.maxValue
val scrollbarOffsetY = firstVisibleElementIndex * elementHeight
val scrollbarHeight = state.viewportSize * elementHeight
drawRect(
color = Color.Red,
topLeft = Offset(this.size.width - width.toPx(), scrollbarOffsetY),
size = Size(width.toPx(), scrollbarHeight),
alpha = alpha
)
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/780 ... ck-compose
Мобильная версия