nuhkoca
03/19/2022, 3:33 PMSuccess
and Error
states already work as expected because they aren’t centered on the screen but LoadingView
should be centered instead but it is always placed on top. How do I fix this? Thank you.
...
Scaffold(topBar = topBar) {
Box(
modifier = Modifier
.padding(it)
.verticalScroll(rememberScrollState())
) {
when (collectionState) {
CollectionState.Loading -> LoadingView()
is CollectionState.Success -> {
ScreenView(
collection = collectionState.collection,
onWatchlistItemClick = onWatchlistItemClick,
onDisclaimerTextClicked = onDisclaimerTextClicked
)
}
CollectionState.Error -> ErrorView(onTryAgainClicked = onTryAgainClicked)
}
}
}
...
@Composable
private fun LoadingView() {
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
) {
CircularProgressIndicator()
}
}
nuhkoca
03/19/2022, 4:24 PMBoxScope
seems to be working but I am not sure if this is a good approach
@Composable
private fun BoxScope.LoadingView() {
Box(modifier = Modifier.align(Alignment.Center)) {
CircularProgressIndicator()
}
}
trashcoder
03/19/2022, 7:18 PMBox(
modifier = Modifier
.padding(it)
.verticalScroll(rememberScrollState())
) {
Arsen
03/19/2022, 7:23 PMScaffold {
BoxWithConstraints(
contentAlignment = Alignment.Center,
modifier = Modifier.fillMaxSize()
) {
Text("w: $maxWidth \nh: $maxHeight")
val size = if (maxWidth < maxHeight) {
maxWidth / 2
} else {
maxHeight / 2
}
CircularProgressIndicator(modifier = Modifier.size(size))
}
}
Arsen
03/19/2022, 7:24 PMnuhkoca
03/19/2022, 9:40 PMAlignment.Center
in the parent box.nuhkoca
03/19/2022, 9:40 PMArsen
03/20/2022, 11:26 AM