Simple-Paging
0.0.1-Alpha03indexedEnables simple pagination for list views, offering functionalities like pagination result observation, data fetching, refreshing, and error handling, inspired by Android Jetpack Paging.
Enables simple pagination for list views, offering functionalities like pagination result observation, data fetching, refreshing, and error handling, inspired by Android Jetpack Paging.
Simple Paging is a Kotlin Multiplatform library for Android, Desktop and iOS that provides simple pagination for list views.
Prerequisites To use Simple Paging, you will need to have the following installed:
Kotlin 1.5.21 or later Gradle 7.0 or later Xcode 12.5 or later (if using the iOS platform)
To install Simple Paging, add the following to your build.gradle.kts file:
dependencies {
implementation("io.github.kashif-e:simple-paging:<version>")
}
Replace with the version of Simple Paging you want to use.
Here is an example of how to use Simple Paging:
// Create a PagingSource
val pagingSource = { MyPagingSource() }
// Create a PaginationResult
paginationResult = coroutineScope.paginate(pagingSourceProvider = pagingSource)
paginationResult.pagedData.collect { result ->
(result) {
Result.Success -> {
= result.
}
Result.Error -> {
error = result.exception
}
Result.Loading -> {
}
Result.PaginationLoading -> {
}
}
}
paginationResult.fetchNextPage()
paginationResult.refresh()
paginationResult.cancel()
Replace MyPagingSource with your own implementation of the PagingSource class.
Sample PagingSource:
Simple Paging is licensed under the MIT License. See the LICENSE file for details.
This library is inspired by the Android Jetpack Paging library.
class MyPagingSource(private val database: MyDatabase) : PagingSource<Int, MyData>() {
override suspend fun load(params: LoadParams<Int>): Result<Page<Int, MyData>> {
return try {
val data = database.loadData(params.key ?: 0, params.loadSize)
val prevKey = if (params.key == 0) null else params.key - 1
val nextKey = if (data.size < params.loadSize) null else params.key + 1
Result.Success(Page(data, prevKey, nextKey))
} catch (exception: Exception) {
Result.Error(exception.message ?: "Something went wrong, please try again.")
}
}
}
Surfaced from shared tags and platforms — no rankings paid for.