
Lightweight library for paging functionality, enabling creation of custom PageContext, PagedDataSource, and PagerCollector. Offers easy integration and extensive documentation for efficient data handling.
klibs.paging — lightweight Kotlin-only library simplifies pagination in your Kotlin Multiplatform projects. Whether
you're building for Android, iOS, JVM, or JS, klibs.paging provides a clean and efficient way to handle paginated
data.
For a practical example, check out the sample directory in the repository. It demonstrates how to implement pagination in a Kotlin Multiplatform project.
Gradle
implementation("ru.astrainteractive.klibs:paging:<version>")
implementation(libs.klibs.paging)Version catalogs
[versions]
klibs-paging = "<latest-version>"
[libraries]
klibs-paging = { module = "ru.astrainteractive.klibs:paging", version.ref = "klibs-paging" }data class IntPageContext(val page: Int) : PageContext {
object Factory : PageContext.Factory<IntPageContext> {
override fun next(pageContext: IntPageContext): IntPageContext {
return pageContext.copy(page = pageContext.page + 1)
}
override fun prev(pageContext: IntPageContext): IntPageContext {
return pageContext.copy(page = pageContext.page - 1)
}
}
}
class IntPagerCollector<T>(
private val initialPage: Int = 0,
private val pager: PagedListDataSource<T, IntPageContext>,
) : PagingCollector<T, IntPageContext> by DefaultPagingCollector(
initialPagingStateFactory = {
PagingState(
pageContext = IntPageContext(page = initialPage),
items = emptyList(),
pageResult = PageResult.Pending
)
},
pager = pager,
pageContextFactory = IntPageContext.Factory
)private val pagingCollector = IntPagerCollector(
initialPage = 0,
pager = {
runCatching {
listOf("Hello first item!")
}
}
)
val state = pagingCollector.pagingState
fun loadItem() {
pagingCollector.loadNextPage()
}If our projects help you, consider supporting their development.
|
Bitcoin |
|
|
Ethereum |
|
|
Boosty |
|
klibs.paging — lightweight Kotlin-only library simplifies pagination in your Kotlin Multiplatform projects. Whether
you're building for Android, iOS, JVM, or JS, klibs.paging provides a clean and efficient way to handle paginated
data.
For a practical example, check out the sample directory in the repository. It demonstrates how to implement pagination in a Kotlin Multiplatform project.
Gradle
implementation("ru.astrainteractive.klibs:paging:<version>")
implementation(libs.klibs.paging)Version catalogs
[versions]
klibs-paging = "<latest-version>"
[libraries]
klibs-paging = { module = "ru.astrainteractive.klibs:paging", version.ref = "klibs-paging" }data class IntPageContext(val page: Int) : PageContext {
object Factory : PageContext.Factory<IntPageContext> {
override fun next(pageContext: IntPageContext): IntPageContext {
return pageContext.copy(page = pageContext.page + 1)
}
override fun prev(pageContext: IntPageContext): IntPageContext {
return pageContext.copy(page = pageContext.page - 1)
}
}
}
class IntPagerCollector<T>(
private val initialPage: Int = 0,
private val pager: PagedListDataSource<T, IntPageContext>,
) : PagingCollector<T, IntPageContext> by DefaultPagingCollector(
initialPagingStateFactory = {
PagingState(
pageContext = IntPageContext(page = initialPage),
items = emptyList(),
pageResult = PageResult.Pending
)
},
pager = pager,
pageContextFactory = IntPageContext.Factory
)private val pagingCollector = IntPagerCollector(
initialPage = 0,
pager = {
runCatching {
listOf("Hello first item!")
}
}
)
val state = pagingCollector.pagingState
fun loadItem() {
pagingCollector.loadNextPage()
}If our projects help you, consider supporting their development.
|
Bitcoin |
|
|
Ethereum |
|
|
Boosty |
|