Hey everybody, I just encountered some bizarre be...
# compose
a
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:
Copy code
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:
Copy code
rememberLazyListState(initialFirstVisibleItemIndex / cellsPerRow)
a
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.
a
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