Pagination made truly small, truly easy to use. The evil, unknown counterpart of... uhm.. some other commonly used pagination library.
// for compose multiplatform or jetpack compose
com.nxoim.evolpagink:compose:<version>
// for diy bindings. core is not bound to any ui framework
com.nxoim.evolpagink:core:<version>
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>>
},
strategy = visibilityAwarePrefetchPageAmount(
// this strategy will use your ui to fetch
// items to fill the viewport + prefetch
// specified amount beyond viewport
initialPage = 0,
pageAmountSurroundingVisible = 2
)
)Aaaaaand then you use it. For example in compose it looks like:
val lazyListState = rememberLazyListState()
val pageableState = yourModel.pageable.toState(
lazyListState,
key = { item -> item.maybeSomeId }
)
LazyColumn(state) {
// this is an overload that automatically
// uses the key lambda from above
items(pageableState) { item ->
YourItem(item)
}
// by the way the overload prevents the
// import fights of items(count: Int)
// vs items(items: List<T>)!!
}Theres a microbenchmark in the repository. Clone the repo and run it. If you find the benchmark unsatisfactory - i'd very much appreciate a discussion in an open issue!
Yes. If you are unsatisfied with any of the stategies 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