is there pagination Library for Compose multi-plat...
# multiplatform
a
is there pagination Library for Compose multi-platform by kotlin?
👀 1
r
Out of curiosity - after IMO a bad API design of Paging 3, I gave up on pagination libraries and just did it myself - would implementing the basics yourself work for your use case? In my use case, I simply check the visible item positions in the list (debounced), then submit a new trigger to the repository if the last visible item is close enough to the end. Then the repository doesn't need a lot of logic to determine if it should load the next page.
👍 1
c
Yeah I would semi tend to agree, Paging3 is a little weird with the API think it took me longer to grep how they designed it, in that time I could of written my own...
👍 1
a
Thanks all 🙏 i had the same opinion would write my custom logic now
👍 1
h
@Rok Oblak can you share the sample the code that your wrote?
r
I do not have it at hand as it was a codebase for another company in the past. In essence: 1. in the composable, you can create a snapshot flow out of
LazyListState
(example). You can map it a bit to receive the right result, i.e. the position of last visible item. 2. With this position, you can then notify your view model and repository about it. The repository uses this information to decide if a new page should be fetched (it knows what the last loaded item position is, so it knows if you scrolled near the end). Nothing complicated there, just basically making sure to debounce the new page load requests, to check that if a page is being loaded you ignore the request, etc. 3. Then all the usual - repo knows how to load the next page, the next page load appends to the list of loaded items, and your composable receives the new list.
👍 1
a
https://gist.github.com/Archer0071/1664967a0e6a881eb52a639e2c8417c6 @hafiz this might help its the code i was working on
h
@Adil thanks. It is grate
@Adil can you share this code:
if (!viewModel.hasHandleScroll.value) {
if (viewModel.monitoredSpaceList.value.size + 10 < viewModel.total) { viewModel.startLoadingMore() viewModel.setEvent(MonitoredSpacesTabContract.Event.OnLoadMore) isLoading = true } else { viewModel.stopLoadingMore() isLoading = false } viewModel.hasHandleScroll(true) } } }
a
Its mutable state flow boolean which is basically checking ui change with respect to back logic since the launced effect code could be triggered many times i.e Edge case a user scrolling up and down repeatedly could trigger launched effect so having viewmodel check can avoid that edge case
h
@Adil can u show logic to update this value:
Copy code
viewModel.hasHandleScroll
how viewModel.hasHandleScroll to set false again after viewModel.hasHandleScroll(true)? @Adil
a
@hafiz handle this on api calls logic when success or failure