Ui

Represents a composable UI for the given UiState. Conventionally, this should just be the return type of a ui function and a thin shim over a "real" implementation.

This has two main benefits:

  1. Discouraging properties and general non-composable state that writing a class may invite.

  2. Ensuring separation of Ui instance from Screen specific ui composables allows for and encourages easy UI previews via Compose's @Preview annotations.

Usage:

internal fun tacoUi(): Ui<State> = ui { state, modifier ->
Tacos(state, modifier)
}

@Composable private fun Tacos(state: State, modifier: Modifier = Modifier) {...}

@Preview
@Composable
private fun PreviewTacos() = Tacos(...)

This could be a class, but isn't necessary unless you're using dependency injection. Most UIs don't use dependency injection at all however, unless maybe getting assisted injections of things like image loaders.

If a given Presenter only ever emits the same state, you can define a single value-less object type for the state.

Note that due to a bug in studio, we can't make this a fun interface yet. Instead, use ui.

See also

Types

Link copied to clipboard
fun interface Factory

A factory that creates Ui's for a given Screen.

Functions

Link copied to clipboard
abstract fun Content(state: UiState, modifier: Modifier)