📱UiState
Example of an UiState for a Dashboard
data class DashboardUiState(
override val action: Consumable<DashboardUiAction>? = null,
val state: ContentState,
) : Actionable<DashboardUiAction> {
sealed interface ContentState {
data object Loading : ContentState
data object Error : ContentState
data class Content(
val title: String,
val description: String
) : ContentState
}
}
Note that DashboardUiState
implements the Actionable
interface for one-time actions sent from the ViewModel to the Fragment, like showing a Dialog or a Snackbar, or navigating to another Screen.
Here's how a child of MVIViewModel
would send an UiAction
to the Screen via its UiState
:
private fun onClickOnNext() {
update { copy(action = Consumable(DashboardUiAction.NavigateToNext)) }
}
Last updated