Автор статьи написал простое DSL для упрощения работы с пагинацией через JetPack Paging3, вместо решения в лоб от Google. Исходны код на
@Composable
fun ArticlesPage(
articles: LazyPagingItems<Article>,
onAction: (NewsListAction) -> Unit,
) {
val newsListState = rememberLazyListState()
HandlePagingItems(articles) {
onRefresh { CircularProgressIndicator() }
onEmpty { // UI for empty list }
onError { error -> // UI for error }
onSuccess { items ->
LazyColumn(newsListState) {
onPagingItems(key = { it.id }) { article -> // UI for article }
onAppendItem { CircularProgressIndicator(Modifier.padding(6.dp)) }
onLastItem { // UI for end of the list }
}
}
}
}
#compose #dsl
Please open Telegram to view this post
VIEW IN TELEGRAM
🔥43👍10