nesyou01 / LazyStaggeredGrid

A Jetpack Compose library to achieve staggered grid view
51 stars 2 forks source link

the State object doesn't work as expected #10

Open mykola-dev opened 2 years ago

mykola-dev commented 2 years ago

LazyListState doesn't provide valid info. also its behavior is wrong. For example firstVisibleItemIndex provides the index only for left column. also state.scrollToItem() doesn't work as expected. it scrolls to much.

mykola-dev commented 2 years ago

i actually fixed it by implementing own state facade. internally it works with the LazyListState states collection. so for example if I need to scroll to item 100 in 2 columns grid, I just scroll each column by 100/2 items. for the first visible item I do val firstVisibleItemIndex: Int get() = states.map { it.firstVisibleItemIndex }.fold(0) { acc, i -> acc + i } the code isn't ready for a PR, so can't share right now. I'll push it when have some time.