Handle mutually exclusive states in the state #2116
-
How to handle mutually exclusive states? Lets consider a screen that transitions from sealed class UiState {
data class UserInput(
val age: Int,
val firstName: String,
val secondName: String,
val phone: String,
): UiState()
data class InputConfirmation(
val age: Int,
val name: String,
val phone: String,
): UiState()
}
@Composable
fun present(): UiState {
// How to handle the different mutually exclusive states?
} I actually want to create a separate class to handle them separately. @Stable
class UserInputState() {
private val state = mutableStateOf( UserInput.Empty )
fun state() = state.value
fun handleAction() = TODO()
} My main concern is handling the transitions in the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
If I'm following the example correctly, I think you just output Some event/action performs a mutation in the |
Beta Was this translation helpful? Give feedback.
Oh, just standard conditional logic and some internal state/values to determine the UI state.
The "Tacos" sample shows this for moving though the sub states, and the "Star" sample shows this for loading data.