Colton Idle
07/08/2021, 5:13 AMColton Idle
07/08/2021, 5:14 AMColumn(
Modifier.fillMaxSize().weight(1f),
verticalArrangement = Arrangement.Bottom,
horizontalAlignment = Alignment.CenterHorizontally) {
Crossfade(targetState = viewModel.state.userIsLoading) {
loading ->
when (loading) {
true -> {
CircularProgressIndicator()
}
false -> {
Button(
onClick = { viewModel.doThing() },
) { Text(text = "Do thing") }
}
}
}
}Colton Idle
07/08/2021, 5:16 AMColton Idle
07/08/2021, 5:17 AMColumn(
Modifier.fillMaxSize().weight(1f),
verticalArrangement = Arrangement.Bottom,
horizontalAlignment = Alignment.CenterHorizontally) {
if (viewModel.state.userIsLoading) {
CircularProgressIndicator()
} else {
Button(
onClick = { viewModel.doThing() },
) { Text(text = "Do thing") }
}
}Albert Chang
07/08/2021, 5:26 AMCrossfade resizes according to the content. When cross fading is in progress, both contents are shown so the biggest size is used, and after the button is disposed, the size shrinks to the progress indicator's size.
To fix this, Crossfade need to have a fixed size.Colton Idle
07/08/2021, 5:41 AMAlbert Chang
07/08/2021, 5:45 AMCrossfade it won't be automatically matching parent size.Colton Idle
07/08/2021, 2:18 PMZach Klippenstein (he/him) [MOD]
07/08/2021, 2:25 PMwrapContentSize with center alignment on the progress indicator?Colton Idle
07/08/2021, 2:26 PMAlbert Chang
07/08/2021, 2:38 PMAlbert Chang
07/08/2021, 2:44 PMBox and put it inside Crossfade. Also Modifier.fillMaxSize().weight(1f) doesn't seem to make sense. Modifier.fillMaxSize() should be enough.Colton Idle
07/09/2021, 3:38 AMCrossfade(
modifier = Modifier.fillMaxSize().align(CenterHorizontally),
targetState = viewModel.state.loading) { loading ->
when (loading) {
true -> {
Box(
Modifier.fillMaxSize(),
contentAlignment = Alignment.BottomCenter) {
MyCustomTheme { CircularProgressIndicator() }
}
}
false -> {
Box(
Modifier.fillMaxSize(),
contentAlignment = Alignment.BottomCenter) {
MyButton(
onClick = { viewModel.doThing() },
text = "Do thing")
}
}
}
}
This was more work than I thought. 😭Albert Chang
07/09/2021, 3:56 AMCrossfade(targetState = viewModel.state.loading) { loading ->
Box(
Modifier.fillMaxSize(),
contentAlignment = Alignment.BottomCenter
) {
when (loading) {
true -> MyCustomTheme { CircularProgressIndicator() }
false -> MyButton(
onClick = { viewModel.doThing() },
text = "Do thing"
)
}
}
}Albert Chang
07/09/2021, 3:58 AMAlignment.BottomCenter but considering that the size of the button can grow or shrink according to the text's length and size I think using Alignment.Center may be better.Colton Idle
07/09/2021, 4:12 AMAlbert Chang
07/09/2021, 4:15 AMColton Idle
07/09/2021, 4:16 AMColton Idle
07/09/2021, 4:16 AM