Pagination made truly small, truly easy to use. The evil, unknown counterpart of... uhm.. some other commonly used pagination library.
Important
Quick start in documentation.
First of all - the amount of source code is small.
But regarding the amount of boilerplate - you define your pageable source:
val pageable = pageable(
coroutineScope,
onPage = { index ->
yourSource.getPage(index)
// getPage is Flow<List<YourItem>>
},
pageItemKey = { item -> item.id },
strategy = prefetchPageAmount(
// this strategy will use your ui to fetch
// items to fill the viewport + prefetch
// specified minimumPageAmount beyond viewport
initialPage = { 0 },
minimumPageAmount = 2
)
)Aaaaaand then you use it. For example in compose it looks like:
val lazyListState = rememberLazyListState()
val pageableState = yourModel.pageable.toState(lazyListState)
// don't forget to bind the list state
LazyColumn(lazyListState) {
// this is an overload that, by default,
// sets the keys using uses the item id lambda
// from pageable declaration in the model
items(pageableState) { item ->
YourItem(item)
}
// by the way the overload prevents the
// import fights of items(count: Int)
// vs items(items: List<T>)!!
}In early testing the performance of evolpagink in similar tasks is roughly 2x faster than Paging3 on emulated android. To run the benchmark just clone the repo and see the benchmarks module. If you find the benchmarks unsatisfactory - a new discussion opened in the issues section would be much appreciated!
Yes. If you are unsatisfied with any of the strategies for fetching and prefetching items - you can easily create your own by implementing PageFetchStrategy. You can tailor the behavior precisely.
- evolpagink is Compose Multiplatform first, but the core logic being platform agnostic leaves room for compatibility with other UI frameworks
- If the library becomes unmaintained - forking and maintaining it yourself should be easy due to the small size and code being mostly self documenting
To contribute:
- First open an issue and describe your contribution so it can be discussed
- Then link the branch of your fork, containing the contribution, in the issue
- And then the contribution may be merged
Kudos to the Tiler project for being an inspiration and for the benchmark