I have a Row with two buttons, each setting a different state (SomeState.FirstState or SomeState.SecondState) when clicked. Depending on the state, I want to show a different composable, with smooth transitions between them.
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceEvenly
) {
Button(onClick = {
state = SomeState.FirstState
}) {
Text(text = "Set first state")
}
Button(onClick = {
state = SomeState.SecondState("Second state text")
}) {
Text(text = "Set second state")
}
}
AnimatedVisibility(
visible = state is SomeState.SecondState,
modifier = Modifier.align(Alignment.CenterHorizontally)
) {
if (state is SomeState.SecondState) {
SecondStateText(state = state as SomeState.SecondState)
}
}
The problem is that when SomeState.FirstState is set, the previous composable abruptly disappears. How can I smoothly transition between the composables when switching states, to provide a better user experience?