LazyStaggeredGrid
LazyStaggeredGrid copied to clipboard
Does it support compose paging library?
Can I use this library with paging flow source instead of fixed list?
I don't think so. StaggeredGridScope
has no method that accepts the PagingData<_, _>
instance. Would it be possible to add support? @nesyou01
i created one. similarly how it's done in LazyColumn
import androidx.compose.runtime.Composable
import androidx.paging.compose.LazyPagingItems
import com.nesyou.staggeredgrid.StaggeredGridScope
fun <T : Any> StaggeredGridScope.pagedItems(
items: LazyPagingItems<T>,
itemContent: @Composable StaggeredGridScope.(value: T?) -> Unit
) {
items(
count = items.itemCount,
) { index ->
itemContent(items[index])
}
}
not sure if it's optimal though. i'm pretty new to compose.
I think to make this properly work in all use-cases, the extension function definitely needs a key
parameter. Else animations and add/remove operations might not behave correctly. If I understand it correctly, dynamically mutating the view would de-sync the PagingData
, since without any specific key parameter (as linked below), the index is used as the key and for fetching new data.
https://github.com/androidx/androidx/blob/0d7d221b4aedee1f8d8f27fc1d4f43508de6067a/paging/paging-compose/src/main/java/androidx/paging/compose/LazyPagingItems.kt#L279-L336
This needs an underlying change in the library, since it does not support keys right now.