ScaffoldSnackbars

class ScaffoldSnackbars(val hostState: SnackbarHostState, scope: CoroutineScope)(source)

The snackbars of the Toolkit scaffold around a screen: a page's frame or the shell's tabs. The scaffold draws them above its bottom bar, its floating action buttons and the system bars; the screen only says what to show.

val snackbars = rememberScaffoldSnackbars()
Button(onClick = {
snackbars.post(
message = context.getString(R.string.deleted),
actionLabel = context.getString(R.string.undo),
onAction = { viewModel.onEvent(Event.Undo) },
)
})

A new snackbar replaces the one showing. Each can take the ToolkitSnackbarStyle.Normal or ToolkitSnackbarStyle.Error look, an icon, colours of its own, or be drawn entirely by the screen through content.

Constructors

Link copied to clipboard
constructor(hostState: SnackbarHostState, scope: CoroutineScope)

Properties

Link copied to clipboard

The scaffold's host, for code written against Material's API.

Functions

Link copied to clipboard
fun dismiss()

Hides the snackbar showing, if any.

Link copied to clipboard
fun post(message: String, style: ToolkitSnackbarStyle = ToolkitSnackbarStyle.Normal, actionLabel: String? = null, withDismissAction: Boolean = true, duration: SnackbarDuration? = null, icon: ToolkitIcon? = null, colors: ToolkitSnackbarColors? = null, content: @Composable (SnackbarData) -> Unit? = null, onAction: () -> Unit? = null, onDismiss: () -> Unit? = null): Job

Shows a snackbar from anywhere, a click handler included, without waiting for it: onAction runs if its action is performed, onDismiss if it leaves otherwise. The parameters are those of show.

Link copied to clipboard
suspend fun show(message: String, style: ToolkitSnackbarStyle = ToolkitSnackbarStyle.Normal, actionLabel: String? = null, withDismissAction: Boolean = true, duration: SnackbarDuration? = null, icon: ToolkitIcon? = null, colors: ToolkitSnackbarColors? = null, content: @Composable (SnackbarData) -> Unit? = null): SnackbarResult

Shows a snackbar and suspends until it leaves, replacing any snackbar showing.