Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Game listing with loading
@Composable
fun GameListing(
games: Flow<PagingData<GameResultsEntity>>
) {
val lazyGameItems = games.collectAsLazyPagingItems()
LazyVerticalGrid(
cells = GridCells.Fixed(2),
content = {
items(lazyGameItems.itemCount) { index ->
lazyGameItems[index]?.let { GameItem(it) }
}
lazyGameItems.apply {
when {
loadState.refresh is
LoadState.Loading -> {
item { LoadingItem() }
item { LoadingItem() }
}
loadState.append is
LoadState.Loading -> {
item { LoadingItem() }
item { LoadingItem() }
}
loadState.refresh is
LoadState.Error -> {}
loadState.append is
LoadState.Error -> {}
}
}
}
)
}
@Composable
fun LoadingItem() {
CircularProgressIndicator(
modifier =
Modifier.testTag("ProgressBarItem")
.fillMaxWidth()
.padding(16.dp)
.wrapContentWidth(
Alignment.CenterHorizontally
)
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment