Ahmed Mourad
05/21/2021, 1:17 AMLazyVerticalGrid
, 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
05/21/2021, 1:33 AMLazyVerticalGrid
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
05/21/2021, 10:55 AM