Hello here. I have implemented paging with compose but instead of using LazyColumn, I wish to use a LazyVerticalGrid with two cells each.How do I use lazyPagingItems in LazyVerticalGrid?
Copy code
val lazyPagingNotes = viewModel.notes.collectAsLazyPagingItems()
a
Andrey Kulikov
05/18/2021, 10:11 AM
it will be possible with the next release of paging-compose
n
Ngenge Senior
05/19/2021, 11:22 AM
Okay great
a
Andrey Kulikov
05/19/2021, 11:24 AM
I meant the one which was released yesterday
k
Kunal Raghav
05/21/2021, 7:01 PM
Hi, were you able to find a solution to this?
Kunal Raghav
05/21/2021, 7:27 PM
I wrote this extension function because I think isn't available yet
Copy code
@ExperimentalFoundationApi
private fun < T : Any> LazyGridScope.itemsIndexed(
lazyItems: LazyPagingItems<T>,
itemContent: @Composable LazyGridScope.(index: Int, value: T?) -> Unit
) {
items(lazyItems.itemCount) { index ->
itemContent(index, lazyItems.getAsState(index).value)
}
}
a
Andrey Kulikov
05/22/2021, 12:56 PM
yes, you have to write this function manually for now. there is a policy which doesn’t allow paging-compose to use api from other artefact (compose:foundation) marked as experimental. but what I meant is that prior to the latest version this code you wrote wouldn’t work and now it works