Ahmed Mourad

    Ahmed Mourad

    1 year ago
    Hey everybody, I just encountered some bizarre behavior and I don't think it's intentional. So when using a
    LazyVerticalGrid
    , you can pass an instance of
    LazyListState
    as a parameter, which itself takes
    initialFirstVisibleItemIndex
    as a parameter:
    LazyVerticalGrid(
        cells = GridCells.Fixed(cellsPerRow),
        state = rememberLazyListState(initialFirstVisibleItemIndex)
    )
    The problem is that the index passed to
    rememberLazyListState
    is used as a row index instead of an item index. So if I pass 5 as
    cellsPerRow
    in the above example, and I pass 7 as the
    initialFirstVisibleItemIndex
    , I would expect the second row to be the top of my list, but instead it's 7th row that is at the top. At this point I usually have to do this to get the correct behavior:
    rememberLazyListState(initialFirstVisibleItemIndex / cellsPerRow)
    Albert Chang

    Albert Chang

    1 year ago
    This is due to the fact that
    LazyVerticalGrid
    uses
    LazyColumn
    internally. It’s consistent with LazyListState’s properties and I think it’s the expected behavior ATM. It’s not clearly documented, though. If you don’t like the current behavior, you can file an issue.
    Andrey Kulikov

    Andrey Kulikov

    1 year ago
    Yes, ideally later we will introduce a separate LazyGridState which works as you expect, we just didn’t have time to make it. Thus this function is marked as experimental now and will kept like this for 1.0, but a planned to be worked on in further versions