Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrollbar doesn't reach end on first drag with LazyColumn with variable height items #2679

Closed
m-sasha opened this issue Jan 29, 2023 · 0 comments · Fixed by JetBrains/compose-multiplatform-core#387
Assignees

Comments

@m-sasha
Copy link
Contributor

m-sasha commented Jan 29, 2023

When the items in a LazyColumn are of varying sizes, it's possible for the scrollbar thumb to not reach the start/end of its area on the first drag gesture.

Reproducer:

fun main() = application {
    Window(
        onCloseRequest = ::exitApplication,
        state = rememberWindowState(width = 300.dp, height = 380.dp)
    ) {
        LazyScrollable()
    }
}

@Composable
private fun LazyScrollable() {
    Box(
        modifier = Modifier
            .fillMaxWidth()
            .background(color = Color.White)
    ) {
        val state = rememberLazyListState()
        val heights = List(4){ 200.dp } + List(10){ 50.dp }

        LazyColumn(
            modifier = Modifier.fillMaxSize(),
            state = state,
        ) {
            items(heights.size) { x ->
                TextBox("Item #$x", x, heights[x])
            }
        }

        VerticalScrollbar(
            modifier = Modifier
                .align(Alignment.CenterEnd)
                .fillMaxHeight(),
            adapter = rememberScrollbarAdapter(
                scrollState = state,
            ),
        )
    }
}

@Composable
fun TextBox(text: String = "Item", index: Int, height: Dp) {
    Box(
        modifier = Modifier
            .height(height)
            .fillMaxWidth()
            .background(
                color = Color(
                    red = (index * 50).mod(255),
                    green = (index * 100).mod(255),
                    blue = (index * 150).mod(255),
                    alpha = 128
                )
            ),
        contentAlignment = Alignment.CenterStart
    ) {
        Text(text = text)
    }
}
Screen.Recording.2023-01-29.at.14.27.53.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant