StateContent

fun <S> StateContent(state: S, modifier: Modifier = Modifier, contentKey: (S) -> Any? = ::caseOf, transition: ContentTransform? = LocalScreenStates.current.transition, label: String = "StateContent", content: @Composable (S) -> Unit)(source)

Draws state with content, animating with transition when its case changes.

The case is contentKey of the state. By default a value of an enum, a Boolean, a number or a string is a case of its own, and any other value is a case by its class, such as a sealed type's subclass: moving from Idle to Cleaning animates, while new data inside the same case does not. Use it for any state a screen switches on, such as the phases of a flow; ScreenStateHandler uses it for a Loadable.

StateContent(state = state.phase) { phase ->
when (phase) {
CleanerPhase.Idle -> CleanerWelcome()
is CleanerPhase.Cleaning -> CleaningProgress(phase.progress)
CleanerPhase.Finished -> CleanerFinished()
}
}

Parameters

transition

How one case replaces another; by default the app's ScreenStates.transition, or a cross-fade on the app's motion scheme when it sets none.