Snackbar

Snackbar

A lightweight message with an optional action that appears at the bottom of the screen.


Installation

./gradlew lumo --add Snackbar

Usage

Basic Snackbar

val snackbarHostState = remember { SnackbarHostState() }
 
Scaffold(
    snackbarHost = {
        SnackbarHost(hostState = snackbarHostState)
    },
    content = { padding ->
        Box(modifier = Modifier.padding(padding)) {
            Button(
                onClick = {
                    scope.launch {
                        snackbarHostState.showSnackbar(
                            message = "Message sent",
                            actionLabel = "Undo"
                        )
                    }
                }
            ) {
                Text("Show Snackbar")
            }
        }
    }
)
 

Custom Snackbar

Snackbar(
    snackbarData = snackbarData,
    shape = RoundedCornerShape(12.dp),
    containerColor = AppTheme.colors.surface,
    contentColor = AppTheme.colors.onSurface,
    actionColor = AppTheme.colors.primary,
    dismissActionContentColor = AppTheme.colors.onSurface
)

API Documentation

Parameters

ParameterTypeDescription
snackbarDataSnackbarDataData for the snackbar
modifierModifierModifier for the snackbar
shapeShapeShape of the snackbar container
containerColorColorBackground color of the snackbar
contentColorColorColor of the message text
actionColorColorColor of the action button
actionContentColorColorColor of the action button text
dismissActionContentColorColorColor of the dismiss action button

SnackbarHostState Methods

MethodParametersDescription
showSnackbarmessage: String
actionLabel: String?
withDismissAction: Boolean
duration: SnackbarDuration
Shows a snackbar with given params

SnackbarDuration

ValueDescription
ShortShows for a short duration (4 seconds)
LongShows for a long duration (10 seconds)
IndefiniteShows until explicitly dismissed