ScreenStateHandler

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)(source)

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

Every case but Loadable.Ready is drawn by the nearest LocalScreenStates, so a screen passes only what differs: its icon, whether an empty result is worth another try, whether the ad shows. A failure always shows something, with a retry button when onRetry is given and the failure is retryable. The animation runs when the case changes, not when the content inside Loadable.Ready does.

Inside a ScreenHost, the loading content stays until the screen's entrance can begin: a result that arrives while the screen is still sliding in waits there, then the loading content fades as the result's elements enter, so the screen is never blank between the two.

ScreenStateHandler(state = state.config, icon = Icons.Outlined.Settings, onRetry = onRetry) { ready ->
SettingsList(ready.value)
}

Use it for one Loadable field of a screen's state; a screen with several draws one each.

Parameters

contentPadding

Padding the loading, empty and failure content keeps, usually the screen's content padding.

onRetry

What the failure content's retry button does; without it there is none.

retryWhenEmpty

Whether the empty content offers onRetry too, for a result that may change, such as a catalog that may have been updated.

icon

The icon of the empty and failure content: any ToolkitIcon, such as a drawable or an animated icon. An overload takes an ImageVector.

showAd

Whether the empty and failure content show their native ad.

onLoading

Replaces the loading content for this section only, such as with a skeleton of its layout.

onEmpty

Replaces the empty content for this section only.

onError

Replaces the failure content for this section only.

onSuccess

Draws the content. It receives the whole Loadable.Ready, so it can mark a refresh or a stale copy.


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)(source)

ScreenStateHandler with an ImageVector icon.