
Wrapping LazyPagingItems into lazy columns that auto-handle loading, empty, error and pull-to-refresh states; exposes resolved paging state so UI code focuses only on state rendering.
A Kotlin Multiplatform library that wraps AndroidX Paging's LazyPagingItems in Compose Multiplatform lazy columns with built-in loading, empty, error, and pull-to-refresh states.
lazy-paging provides two composables that consume a LazyPagingItems<T> and render the right UI for its current paging state:
LazyPagingColumn — a LazyColumn that swaps between loading / empty / error / content slots.RefreshableLazyPagingColumn — the same, wrapped in a Material 3 PullToRefreshBox.State resolution is exposed via the sealed LazyPagingColumnState and computed by rememberLazyPagingColumnState, so you only write UI for the state, not the paging-flag arithmetic.
Add Maven Central in settings.gradle.kts if it isn't there:
dependencyResolutionManagement {
repositories {
mavenCentral()
}
}Then add the dependency (Compose Multiplatform module, typically in commonMain):
kotlin {
sourceSets {
commonMain.dependencies {
implementation("com.felipearpa:lazy-paging:0.0.1")
}
}
}@Composable
fun ItemsScreen(pager: Pager<Int, Item>) {
val lazyPagingItems = pager.flow.collectAsLazyPagingItems()
RefreshableLazyPagingColumn(
modifier = Modifier.fillMaxSize(),
lazyPagingItems = lazyPagingItems,
contentPadding = PaddingValues(16.dp),
loadingContent = { item { CircularProgressIndicator() } },
errorContent = { exception ->
item {
Column {
Text(exception.message ?: "Unknown error")
Button(onClick = { lazyPagingItems.retry() }) { Text("Retry") }
}
}
},
emptyContent = { item { Text("Nothing here yet.") } },
) {
items(
count = lazyPagingItems.itemCount,
key = lazyPagingItems.itemKey { it.id },
) { index ->
lazyPagingItems[index]?.let { ItemRow(it) }
}
}
}A runnable sample lives in sample/ (shared KMP code) and sample-android/ (Android launcher). It exercises bidirectional paging, append/prepend errors, empty results, slow network, and initial-load failures.
Full documentation is available at the project site.
Pull requests and issues are welcome.
This project is licensed under the MIT License.
A Kotlin Multiplatform library that wraps AndroidX Paging's LazyPagingItems in Compose Multiplatform lazy columns with built-in loading, empty, error, and pull-to-refresh states.
lazy-paging provides two composables that consume a LazyPagingItems<T> and render the right UI for its current paging state:
LazyPagingColumn — a LazyColumn that swaps between loading / empty / error / content slots.RefreshableLazyPagingColumn — the same, wrapped in a Material 3 PullToRefreshBox.State resolution is exposed via the sealed LazyPagingColumnState and computed by rememberLazyPagingColumnState, so you only write UI for the state, not the paging-flag arithmetic.
Add Maven Central in settings.gradle.kts if it isn't there:
dependencyResolutionManagement {
repositories {
mavenCentral()
}
}Then add the dependency (Compose Multiplatform module, typically in commonMain):
kotlin {
sourceSets {
commonMain.dependencies {
implementation("com.felipearpa:lazy-paging:0.0.1")
}
}
}@Composable
fun ItemsScreen(pager: Pager<Int, Item>) {
val lazyPagingItems = pager.flow.collectAsLazyPagingItems()
RefreshableLazyPagingColumn(
modifier = Modifier.fillMaxSize(),
lazyPagingItems = lazyPagingItems,
contentPadding = PaddingValues(16.dp),
loadingContent = { item { CircularProgressIndicator() } },
errorContent = { exception ->
item {
Column {
Text(exception.message ?: "Unknown error")
Button(onClick = { lazyPagingItems.retry() }) { Text("Retry") }
}
}
},
emptyContent = { item { Text("Nothing here yet.") } },
) {
items(
count = lazyPagingItems.itemCount,
key = lazyPagingItems.itemKey { it.id },
) { index ->
lazyPagingItems[index]?.let { ItemRow(it) }
}
}
}A runnable sample lives in sample/ (shared KMP code) and sample-android/ (Android launcher). It exercises bidirectional paging, append/prepend errors, empty results, slow network, and initial-load failures.
Full documentation is available at the project site.
Pull requests and issues are welcome.
This project is licensed under the MIT License.