A scrollbar that represents the current scroll position of a scrolling component.
@Composable
fun ScrollbarWithLazyColumnSample() {
val state = rememberLazyListState()
LazyColumn(
state = state,
modifier =
Modifier.fillMaxSize()
.scrollbar(state.scrollIndicatorState, orientation = Orientation.Vertical),
) {
items(100) { index ->
Text(
text = "Item $index",
modifier = Modifier.fillMaxWidth().height(50.dp).wrapContentSize(Alignment.Center),
)
}
}
}
@Composable
fun ScrollbarWithVerticalScrollSample() {
val state = rememberScrollState()
Column(
modifier =
Modifier.fillMaxSize()
// Chain before verticalScroll so the scrollbar doesn't scroll with content.
.scrollbar(state.scrollIndicatorState, orientation = Orientation.Vertical)
.verticalScroll(state)
) {
repeat(100) { index ->
Text(
text = "Item $index",
modifier = Modifier.fillMaxWidth().height(50.dp).wrapContentSize(Alignment.Center),
)
}
}
}