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

ScrollBarAdapter for LazyListState ignores the contentPadding #2604

Closed
m-sasha opened this issue Jan 7, 2023 · 2 comments · Fixed by JetBrains/compose-multiplatform-core#365
Assignees
Labels
bug Something isn't working desktop scroll

Comments

@m-sasha
Copy link
Member

m-sasha commented Jan 7, 2023

The ScrollBarAdapter for LazyListState doesn't take into account the LazyLists contentPadding.

Reproducer:

import androidx.compose.foundation.VerticalScrollbar
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.rememberScrollbarAdapter
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
import androidx.compose.ui.window.rememberWindowState


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


@Composable
fun LazyScrollable() {
    Box(
        modifier = Modifier
            .fillMaxSize()
            .background(color = Color.White)
    ) {

        val state = rememberLazyListState()

        LazyColumn(
            modifier = Modifier.fillMaxSize(),
            state = state,
            contentPadding = PaddingValues(vertical = 100.dp)
        ) {
            items(5) { x ->
                TextBox("Item #$x", x)
            }
        }
        VerticalScrollbar(
            modifier = Modifier.align(Alignment.CenterEnd).fillMaxHeight(),
            adapter = rememberScrollbarAdapter(
                scrollState = state,
            )
        )
    }
}


@Composable
fun TextBox(text: String = "Item", index: Int) {
    Box(
        modifier = Modifier
            .height(130.dp)
            .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-07.at.12.05.56.mp4

As you can see, dragging the scrollbar to the bottom doesn't cause the content to scroll to the bottom.

@m-sasha m-sasha self-assigned this Jan 7, 2023
@m-sasha
Copy link
Member Author

m-sasha commented Jan 7, 2023

This is part of the problems described by #1211

@okushnikov
Copy link
Collaborator

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working desktop scroll
Projects
None yet
2 participants