Last active
August 19, 2021 19:33
-
-
Save rubenquadros/dbff28d1e5abf2b6ecc8de2466cd8e11 to your computer and use it in GitHub Desktop.
Game listing with loading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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