1

I have the same question as asked in this StackOverflow question, but for Jetpack Compose.

How can we get a list of items in Jetpack Compose when you're using Paging3 with LazyVerticalGrid, As using LazyVerticalGrid, we don't create any PagingDataAdapter.

Abhishek Kumar
  • 4,532
  • 5
  • 31
  • 53

1 Answers1

0

LazyPagingItems has the equivalent presenter APIs from PagingDataAdapter.

To get the whole list you can use LazyPagingItems.itemSnapshotList()

To access an item at a specific index without triggering page fetch, you can use LazyPagingItems.peek

dlam
  • 3,547
  • 17
  • 20
  • How do you use itemSnapshotList() if you want to collect it in a viewModel as collectAsLazyPagingItems() can only be invoked from a composable function? – Akram Hussain May 24 '22 at 18:39
  • @AkramHussain What do you want to accomplish by collecting the state in the viewModel? – dlam May 27 '22 at 08:24
  • I want to make an API request for a batch of items in the list. – Akram Hussain May 27 '22 at 13:01
  • I've been using ItemSnapshotList to access some fields with each item, but that kills automated pagination when using LazyPagingItems. I've had some success with peek and get, but if at the end of the list even peek will fail if I try to access an item beyond the end of the list to see another page will be loaded. How should I be checking for paginating when using the snapshot list? – Martin Dec 05 '22 at 23:51
  • @Martin what are you trying to achieve? Are you trying to manually trigger loading of the next page? – dlam Dec 07 '22 at 00:11