Package-level declarations

Types

Link copied to clipboard
fun interface EntranceCue

Tells a screen that the transition bringing it in is far enough along for its entrance to begin, so its content arrives as the screen lands rather than after it. reached is read inside a snapshot, so it should read state. The shell provides one for each page and tab.

Link copied to clipboard

When a screen's entrance plays. None of them replays it on returning from the background, on a rotation, or for an item scrolled back into view within the visit.

Link copied to clipboard
sealed interface Loadable<out T> : TrackedStatus

The status of one piece of content that loads: the Toolkit's default, used as a field of a screen's state rather than for the whole screen.

Link copied to clipboard
abstract class LoggedScreenViewModel<S, E : Any>(initialState: S, telemetryRepository: TelemetryRepository, screenName: String, viewModelName: String = screenName) : ScreenViewModel<S, E>

A ScreenViewModel that reports to Firebase: a breadcrumb when it is created and for every event, and for each operation a start breadcrumb and vm_op_start event, and on failure an error breadcrumb, a vm_op_error event and a Crashlytics report.

Link copied to clipboard
class ScreenStates(val loading: @Composable (StateSlot) -> Unit = { slot -> LoadingScreen(paddingValues = slot.contentPadding) }, val empty: @Composable (StateSlot, Loadable.Empty) -> Unit = { slot, empty -> NoDataScreen( message = empty.message?.asString(), icon = slot.icon, showRetry = slot.onRetry != null, onRetry = { slot.onRetry?.invoke() }, showAd = slot.showAd, paddingValues = slot.contentPadding, ) }, val failed: @Composable (StateSlot, Loadable.Failed) -> Unit = { slot, failed -> NoDataScreen( message = failed.message.asString(), icon = slot.icon, isError = true, showRetry = slot.onRetry != null, onRetry = { slot.onRetry?.invoke() }, showAd = slot.showAd, paddingValues = slot.contentPadding, ) }, val transition: ContentTransform? = null)

How an app draws loading, empty and failed content, and how one case replaces another. Every ScreenStateHandler and StateContent follows the nearest LocalScreenStates, so an app sets its own once around its content and every screen follows; a single section passes its own onLoading, onEmpty or onError instead.

Link copied to clipboard
abstract class ScreenViewModel<S, E : Any>(initialState: S) : ViewModel

Base ViewModel for a screen: owns its state S, handles its events E, and queues the messages it shows.

Link copied to clipboard
data class StateSlot(val contentPadding: PaddingValues, val icon: ToolkitIcon, val onRetry: () -> Unit?, val showAd: Boolean)

What a ScreenStateHandler knows when it draws a case other than Loadable.Ready.

Link copied to clipboard
interface TrackedStatus

A status that ScreenHost reports in the screen_state analytics event.

Link copied to clipboard
data class UiMessage(val text: UiText, val isError: Boolean = false, val actionLabel: UiText? = null, val id: Long = nextId.incrementAndGet())

A message a screen shows in a snackbar, queued with ScreenViewModel.showMessage.

Properties

Link copied to clipboard

The text every screen shows for a failure it has nothing more specific to say about.

Link copied to clipboard

Whether trying the same operation again can succeed.

Link copied to clipboard

The EntranceCue of the screen here. Without one, a screen's entrance begins once it is resumed, its transition over.

Link copied to clipboard

The app's EntranceReplay, EntranceReplay.OnOpen unless the app picks another. The shell provides the app's choice, appToolkitDefaults { shell { entranceReplay = ... } }, or the one picked in the developer options.

Link copied to clipboard

How many times the screen here has been opened again while it stayed in its back stack, such as a tab picked again from the navigation bar or rail. The shell provides it around each tab's screens. When it changes, EntranceReplay.OnOpen plays the screen's entrance again; going back to the screen leaves it as it is, so it does not.

Link copied to clipboard

Functions

Link copied to clipboard
fun MessageHost(viewModel: ScreenViewModel<*, *>, snackbarHostState: SnackbarHostState = rememberPageSnackbarHostState(), onAction: (UiMessage) -> Unit = {}, drawHost: Boolean = snackbarHostState !== LocalPageSnackbarHostState.current)

Shows viewModel's queued messages, one at a time and in order, and tells it as each leaves.

fun MessageHost(messages: ImmutableList<UiMessage>, onShown: (id: Long) -> Unit, snackbarHostState: SnackbarHostState = rememberPageSnackbarHostState(), onAction: (UiMessage) -> Unit = {}, drawHost: Boolean = snackbarHostState !== LocalPageSnackbarHostState.current)

Shows messages one at a time, oldest first, calling onShown with each one's id once it has left. A message still on screen when this leaves composition is not marked as shown, so it shows again next time rather than being lost.

Link copied to clipboard
fun MessageToastHost(messages: ImmutableList<UiMessage>, onShown: (id: Long) -> Unit, errorDuration: Int = Toast.LENGTH_LONG)

Posts queued messages as toasts when a sheet would cover the page's snackbar. Toasts have no actions.

Link copied to clipboard
fun ScreenHost(screen: TrackedScreen, status: TrackedStatus? = null, viewModel: ScreenViewModel<*, *>? = null, onMessageAction: (UiMessage) -> Unit = {}, fabs: List<ToolkitFab>? = null, content: @Composable () -> Unit)

The boundary of one screen: reports each visit to it, reports its status, and shows its ViewModel's messages. Every screen, tab, page, sheet or pane with a screen name of its own is wrapped in one.

Link copied to clipboard
fun <T> ScreenStateHandler(state: Loadable<T>, modifier: Modifier = Modifier, contentPadding: PaddingValues = PaddingValues(), onRetry: () -> Unit? = null, retryWhenEmpty: Boolean = false, icon: ToolkitIcon = ToolkitIcon.Vector(Icons.Default.Info), showAd: Boolean = true, onLoading: @Composable () -> Unit = { DefaultLoading(contentPadding, icon, showAd) }, onEmpty: @Composable (Loadable.Empty) -> Unit = { empty -> DefaultEmpty(empty, contentPadding, icon, onRetry.takeIf { retryWhenEmpty }, showAd) }, onError: @Composable (Loadable.Failed) -> Unit = { failed -> DefaultFailed(failed, contentPadding, icon, onRetry.takeIf { failed.retryable }, showAd) }, onSuccess: @Composable (Loadable.Ready<T>) -> Unit)

Draws state, animating between its cases with the app's ScreenStates.

fun <T> ScreenStateHandler(state: Loadable<T>, icon: ImageVector, modifier: Modifier = Modifier, contentPadding: PaddingValues = PaddingValues(), onRetry: () -> Unit? = null, retryWhenEmpty: Boolean = false, showAd: Boolean = true, onLoading: @Composable () -> Unit = { DefaultLoading(contentPadding, ToolkitIcon.Vector(icon), showAd) }, onEmpty: @Composable (Loadable.Empty) -> Unit = { empty -> DefaultEmpty(empty, contentPadding, ToolkitIcon.Vector(icon), onRetry.takeIf { retryWhenEmpty }, showAd) }, onError: @Composable (Loadable.Failed) -> Unit = { failed -> DefaultFailed(failed, contentPadding, ToolkitIcon.Vector(icon), onRetry.takeIf { failed.retryable }, showAd) }, onSuccess: @Composable (Loadable.Ready<T>) -> Unit)
Link copied to clipboard
fun <S> StateContent(state: S, modifier: Modifier = Modifier, contentKey: (S) -> Any? = ::caseOf, transition: ContentTransform? = LocalScreenStates.current.transition, label: String = "StateContent", content: @Composable (S) -> Unit)

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

Link copied to clipboard
fun Throwable.toErrorMessage(fallback: UiText = GenericErrorText): UiMessage

This failure as an error UiMessage: toUiText with fallback.

Link copied to clipboard
fun Throwable.toFailed(fallback: UiText = GenericErrorText, retryable: Boolean = isRetryable): Loadable.Failed

This failure as the Loadable.Failed state of a screen's content: toUiText with fallback, and a retry when retryable.

Link copied to clipboard
fun Throwable.toUiText(fallback: UiText = GenericErrorText): UiText

The text a screen shows for this failure.