I'm looking into using the paging 3 library for handling paging on my android app. One small hitch is that every single example I find assumes I'd always provide a page number to the API when my company uses skip/take for our APIs as does a few other APIs I use that's not under my control.
I see that paging 2 had something but it looks to be depreciated so I'm curious what their solution is for paging 3?
By skip/take do you mean you have a item-keyed source which wants a number of items to load and an offset as inputs?
In Paging2 there were explicit classes for each type of key, but in Paging3 you control how the key is interpreted directly, so you can implement a PagingSource using the offset as the key.
Naively, just to show nextKey
calculation:
class MyPagingSource : PagingSource<Int, Item>() {
override suspend fun load(params: LoadParams) {
...
val data = api.load(offset = params.key, size = params.loadSize)
return LoadResult.Page(
...
prevKey = ...
nextKey = data.size() + params.key
)
}
...
}
Note: You will still need to implement prepend if you want to support that, error handling, and getRefreshKey