Skip to main content

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.

  • inverseSurface container, inverseOnSurface text in bodyMedium.
  • 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 for Error/Success/…
  • typography.bodyMedium, labelLarge (action), shapes.extraSmall, elevation.level3
  • motion.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.

FieldTypeMaterial defaultWhat it's for
shapeShapeshapes.extraSmallcorners
maxWidthDp560centered on wide windows
marginPadding16distance from the edges
positionBottom | TopBottomwhere snackbars appear, on every window size (ADR-28: a brand choice)
showDismissBooleanfalsean ✕ on every snackbar when a call passes no withDismiss
showToneIconBooleanfalsea leading status icon for Error / Success / Warning / Info (the same default icons as CamoBanner)
durationShort / LongDuration4 s / 10 stiming
colorsSnackbarColors(container, text, action)inverseSurface, inverseOnSurface, inversePrimarycolors for tone = Default

Accessibility​

  • It's announced politely when shown (a live region). Error tone 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​

  1. CamoMessenger (queue, timers paused while pressed or hovered), installed by the root provider, and CamoMessengerInsets.
  2. SnackbarRenderer, and the DebugSkin renderer.
  3. Sample: archive with Undo, an error with Retry, and several queued messages.
  4. Tests:
    • show returns ActionPerformed when the action is tapped;
    • timeout → Dismissed;
    • messages queue in order;
    • the insets lift it above a navigation bar; with position = Top it sits below the status bar and top inset;
    • withDismiss = null follows showDismiss; showToneIcon draws 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​

CaseDecided behavior
Showing from a ViewModel/notifierThrough 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 openThe snackbar appears above the scrim (the messenger layer is above overlays), so it's not hidden.
Many rapid messagesQueued. 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 iconsWith 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 webBottom-start (Material desktop convention) on wide windows. It's a skin decision via position and alignment.
Changed in the M7 build (2026-10-28)
  • SnackbarTheme gains alignment (Start / Center / End along the edge; Fluent's toast is bottom-end), padding, minHeight, textStyle, actionStyle, elevation, dismissIcon and strings; the durations are durationShortMillis / durationLongMillis on Kotlin and Durations on Flutter.
  • The state is SnackbarState(message, action, tone, withDismiss, showToneIcon, position, interaction), and core builds SnackbarSlots(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: show acquires a Mutex, publishes the current message as state, and waits in suspendCancellableCoroutine for the action, dismiss or timeout. Cancelling the calling coroutine (the page leaves) removes that message.
  • Timeouts: Short 4 s, Long 10 s, Auto picks by action; the value is passed through LocalAccessibilityManager.current?.calculateRecommendedTimeoutMillis(ms, containsIcons, containsText, containsControls = action != null), so screen-reader users get longer (or indefinite) time. Timers pause while pressed or hovered.
  • Host: Box aligned BottomCenter or TopCenter per style.position, padded by system insets plus the nearest CamoMessengerInsets; widthIn(max = style.maxWidth). Enter/exit slide from the chosen edge. Swipe to dismiss uses anchoredDraggable horizontally (and up for Top).
  • Announcements: the snackbar node has liveRegion = LiveRegionMode.Polite (Assertive for Tone.Error).
  • Tone icon: when style.showToneIcon, the renderer draws BannerTheme.toneIcons for 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​

  1. CamoMessenger + CamoMessengerImpl, LocalCamoMessenger, the host layer installed by the root provider, CamoMessengerInsets.
  2. SnackbarTheme / Style, the DebugSkin renderer.
  3. 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​

CaseDecided 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 providersOnly the root provider installs the messenger; nested providers reuse it, so snackbars don't stack per section.
A dialog is openThe host layer is above the overlay layer, so the snackbar stays visible.
Changed in the M7 build (2026-10-28)
  • The root CamouflageProvider installs 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).
  • CamoMessengerInsets registers with the messenger while its screen is composed; the latest one wins.