@Composable fun StaggeredLayoutWithPagination() { val lazyPagingItems = rememberPagingItems( pagingSourceFactory = { MyPagingSource() } )
val gridState = rememberLazyListState()
LazyVerticalGrid( cells = GridCells.Adaptive(128.dp), state = gridState ) { items(lazyPagingItems) { item -> // Render your items here } }
LazyVerticalGridPagination( lazyPagingItems = lazyPagingItems, state = gridState, onReachedEnd = { lazyPagingItems.loadAround(gridState.lastVisibleItemIndex) } ) }
class MyPagingSource : PagingSource
val data = fetchData(currentPage, loadSize)
return LoadResult.Page(
data = data,
prevKey = null,
nextKey = currentPage + 1
)
}
override suspend fun loadAfter(params: LoadParams
val data = fetchData(currentPage, loadSize)
return LoadResult.Page(
data = data,
prevKey = currentPage,
nextKey = currentPage + 1
)
}
private suspend fun fetchData(page: Int, pageSize: Int): List