Paging in Compose Lists
Render paged data with LazyColumn.
Rendering Paged Data in Compose
The data layer hands you a Flow<PagingData<Article>>. The paging-compose library turns that flow into something a LazyColumn can render, complete with on-demand loading as the user scrolls.
The key bridge is collectAsLazyPagingItems().
collectAsLazyPagingItems
Call collectAsLazyPagingItems() on the flow inside a composable. It returns a LazyPagingItems object that tracks the loaded items and load states, recomposing the UI as pages arrive.
import androidx.paging.compose.collectAsLazyPagingItems
@Composable
fun ArticleScreen(viewModel: ArticleViewModel) {
val articles = viewModel.articles.collectAsLazyPagingItems()
ArticleList(articles)
}All lessons in this course
- Why Paging
- PagingSource and Pager
- Paging in Compose Lists
- RemoteMediator and Caching