CamoSnackbar
Concept
1. Why
A snackbar (toast) is a brief message at the bottom of the screen, optionally with one action: "Message archived · Undo". It's shown, not placed, from anywhere in the app, and messages queue one after another. In Flutter that's ScaffoldMessenger, which lives in Material. In Compose it's SnackbarHostState, which also lives in Material. Camouflage needs its own small messenger, installed once by the root provider, so snackbars work with any skin.
2. Shape
Material mapping preview: the M3 snackbar.
inverseSurfacecontainer,inverseOnSurfacetext inbodyMedium.- The action in
inversePrimary. shapes.extraSmall, 48 min height, 16 from the bottom edge.
3. API
Contract
interface CamoMessenger {
suspend fun show( // Dart: Future<SnackbarResult> show(…)
message: String,
action: String? = null,
tone: Tone = Default, // Error → error-tinted snackbar
duration: SnackbarDuration = Auto, // Short 4 s | Long 10 s | Indefinite | Auto (Short, or Long with an action)
withDismiss: Boolean? = null, // an ✕ button; null → SnackbarTheme.showDismiss
): SnackbarResult // ActionPerformed | Dismissed
fun dismissCurrent()
}
// access: Camouflage.messenger (Kotlin) / CamoMessenger.of(context) (Flutter)
fun CamoMessengerInsets(bottom: Dp = 0.dp, top: Dp = 0.dp, content: Slot) // keeps snackbars clear of a bottom bar or FAB (Bottom) or a top bar (Top)
State → renderer: SnackbarState(message, action?, tone, withDismiss, showToneIcon, position). Slots: none (the action and ✕ are core-built buttons that the renderer places).
Tokens used
colors.inverseSurface,inverseOnSurface,inversePrimary, and the tone family forError/Success/…typography.bodyMedium,labelLarge(action),shapes.extraSmall,elevation.level3motion.durationMedium(slide + fade)
Component theme
theme.components.snackbar: SnackbarTheme?. Every field is nullable in the theme. The skin's defaults(theme) fills whatever isn't set (Material defaults shown). See Theme §3.10.
| Field | Type | Material default | What it's for |
|---|---|---|---|
shape | Shape | shapes.extraSmall | corners |
maxWidth | Dp | 560 | centered on wide windows |
margin | Padding | 16 | distance from the edges |
position | Bottom | Top | Bottom | where snackbars appear, on every window size (ADR-28: a brand choice) |
showDismiss | Boolean | false | an ✕ on every snackbar when a call passes no withDismiss |
showToneIcon | Boolean | false | a leading status icon for Error / Success / Warning / Info (the same default icons as CamoBanner) |
durationShort / Long | Duration | 4 s / 10 s | timing |
colors | SnackbarColors(container, text, action) | inverseSurface, inverseOnSurface, inversePrimary | colors for tone = Default |
Accessibility
- It's announced politely when shown (a live region).
Errortone uses an assertive announcement. - When a screen reader is on, durations follow the platform's recommended accessibility timeout, or stay until dismissed with an action. Users must have time to reach the action (WCAG 2.2.1).
- The action is reachable by keyboard (a focus shortcut on desktop is Later). A swipe or the ✕ dismisses it.
4. Build steps
CamoMessenger(queue, timers paused while pressed or hovered), installed by the root provider, andCamoMessengerInsets.SnackbarRenderer, and the DebugSkin renderer.- Sample: archive with Undo, an error with Retry, and several queued messages.
- Tests:
showreturnsActionPerformedwhen the action is tapped;- timeout →
Dismissed; - messages queue in order;
- the insets lift it above a navigation bar; with
position = Topit sits below the status bar andtopinset; withDismiss = nullfollowsshowDismiss;showToneIcondraws the tone's icon;- the screen-reader timeout rule.
Done when
- Undo and Retry flows work from a ViewModel/notifier effect, on every platform.
5. Edge cases
| Case | Decided behavior |
|---|---|
| Showing from a ViewModel/notifier | Through your Effect pattern: the screen collects the effect and calls messenger.show(…), then sends the result back as an event. |
| A dialog or sheet is open | The snackbar appears above the scrim (the messenger layer is above overlays), so it's not hidden. |
| Many rapid messages | Queued. dismissCurrent() lets an app replace an outdated message. |
position = Top (settled 2026-09-27) | Below the status bar and cutouts, plus CamoMessengerInsets(top) (e.g. below a top bar). It enters from the top and is dismissed by swiping up. Queue and timing are the same as bottom. |
| Tone icons | With showToneIcon, the icon is decorative (the tone is already in the announcement for Error). Custom icons per tone come from BannerTheme's tone icons, so banners and snackbars match. |
| Snackbars on desktop and web | Bottom-start (Material desktop convention) on wide windows. It's a skin decision via position and alignment. |
SnackbarThemegainsalignment(Start/Center/Endalong the edge; Fluent's toast is bottom-end),padding,minHeight,textStyle,actionStyle,elevation,dismissIconandstrings; the durations aredurationShortMillis/durationLongMillison Kotlin andDurations on Flutter.- The state is
SnackbarState(message, action, tone, withDismiss, showToneIcon, position, interaction), and core buildsSnackbarSlots(icon, action, dismiss): the tone icon, the action button and the ✕ (a field action). The renderer provides their colors as the content color, so a skin chooses its own action color: Minimal's inverse snackbar takes the tone's fill, while Fluent's toast stays neutral and shows the tone in its icon. - The timer pauses while the snackbar is hovered, focused or dragged.
- Found in the build: core's action and ✕ must be their own accessibility nodes, or the screen reader merges them into the snackbar's.
Implementation
1. Why
Snackbars are shown imperatively (show() returns the result), unlike every other component. Kotlin implements CamoMessenger as a suspending queue owned by the root CamouflageProvider, with a host layer above overlays. Material's SnackbarHostState isn't used (no Material in v1).
2. Shape
3. API
public interface CamoMessenger {
public suspend fun show(
message: String,
action: String? = null,
tone: Tone = Tone.Default,
duration: SnackbarDuration = SnackbarDuration.Auto,
withDismiss: Boolean? = null, // null → SnackbarTheme.showDismiss
): SnackbarResult
public fun dismissCurrent()
}
public val Camouflage.messenger: CamoMessenger @Composable get() = LocalCamoMessenger.current
@Composable public fun CamoMessengerInsets(bottom: Dp = 0.dp, top: Dp = 0.dp, content: @Composable () -> Unit)
- Queue:
showacquires aMutex, publishes the current message as state, and waits insuspendCancellableCoroutinefor the action, dismiss or timeout. Cancelling the calling coroutine (the page leaves) removes that message. - Timeouts:
Short4 s,Long10 s,Autopicks by action; the value is passed throughLocalAccessibilityManager.current?.calculateRecommendedTimeoutMillis(ms, containsIcons, containsText, containsControls = action != null), so screen-reader users get longer (or indefinite) time. Timers pause while pressed or hovered. - Host:
BoxalignedBottomCenterorTopCenterperstyle.position, padded by system insets plus the nearestCamoMessengerInsets;widthIn(max = style.maxWidth). Enter/exit slide from the chosen edge. Swipe to dismiss usesanchoredDraggablehorizontally (and up forTop). - Announcements: the snackbar node has
liveRegion = LiveRegionMode.Polite(AssertiveforTone.Error). - Tone icon: when
style.showToneIcon, the renderer drawsBannerTheme.toneIconsfor the tone.
From the page/event/effect pattern:
LaunchedEffect(Unit) {
viewModel.effects.collect { effect ->
if (effect is ArchiveEffect.ShowUndo) {
val result = messenger.show("Archived", action = "Undo")
if (result == SnackbarResult.ActionPerformed) viewModel.onEvent(ArchiveEvent.UndoTapped(effect.id))
}
}
}
4. Build steps
CamoMessenger+CamoMessengerImpl,LocalCamoMessenger, the host layer installed by the root provider,CamoMessengerInsets.SnackbarTheme/Style, the DebugSkin renderer.commonTest(with a test clock): results for action, dismiss and timeout; queue order; cancellation removes a queued message; the accessibility timeout multiplier; the position and insets.
Done when
- Archive-with-Undo and error-with-Retry flows work from view model effects on all targets, at the bottom and with
position = Top.
5. Edge cases
| Case | Decided behavior |
|---|---|
| Rotation while a snackbar is visible (Android) | The message is lost with its coroutine; the effect pattern re-emits only if the app wants. Documented. |
| Nested providers | Only the root provider installs the messenger; nested providers reuse it, so snackbars don't stack per section. |
| A dialog is open | The host layer is above the overlay layer, so the snackbar stays visible. |
- The root
CamouflageProviderinstalls the messenger (Camouflage.messenger); nested providers use it. The host emits nothing while idle and shows each snackbar in a popup created when it shows, so it sits above the dialogs and sheets open then. - The accessibility manager is read outside that popup, which has its own platform locals (a test caught an app-provided one being ignored).
CamoMessengerInsetsregisters with the messenger while its screen is composed; the latest one wins.