Skip to main content

CamoFab

Concept​

1. Why​

A floating action button (FAB) holds a screen's single most important action: compose, add, start. It's Material's signature component. Apple doesn't have one, and neither do Fluent or Carbon, so their skins map it to a prominent circular button, or the app puts the action in a toolbar. It can be extended (icon + label), and collapse to the icon while scrolling.

2. Shape​

Material mapping preview: M3 FABs.

  • Sizes: Small 40, Regular 56, Large 96.
  • Container primaryContainer, with content onPrimaryContainer, at level3.
  • shapes.large (Regular).
  • Extended: 56 tall, with a label in labelLarge.

3. API​

Contract​

fun CamoFab(
icon: Widget,
contentDescription: String, // required; also the label when not extended
onClick: () -> Unit,
text: String? = null, // non-null → extended FAB
expanded: Boolean = true, // extended only: false collapses to the icon (e.g. while scrolling)
visible: Boolean = true, // false → scales out (hide on scroll, ADR-30)
appearance: Appearance? = null, // null → FabTheme.defaultAppearance (skin default: Soft); Soft (primaryContainer) | Solid (primary) | Raised (surface); others fall back to Soft
tone: Tone = Default,
)

Placement is app layout (Camouflage has no scaffold): the sample shows bottom-end with 16 padding, lifted above the navigation bar and the messenger's snackbars via CamoMessengerInsets.

State → renderer: FabState(extended, expanded, visible, appearance, tone, interaction). Slots: FabSlots(icon, text?).

Tokens used​

  • the tone family (container/onContainer for Soft, strong/onStrong for Solid), surfaceContainerHigh (Raised)
  • shapes.large (Regular), shapes.medium (Small), shapes.extraLarge (Large)
  • elevation.level3 (resting), level4 (hover)
  • typography.labelLarge, motion.durationMedium (expand/collapse)

Component theme​

theme.components.fab: FabTheme?. 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
defaultAppearanceAppearanceSoftthe appearance used when a call passes none (ADR-28: a brand's default variant)
sizeFabSize (Small | Regular | Large)Regularwhich size the FAB uses (ADR-23: only Material has three sizes, so it's a theme choice, not a parameter). One screen can switch with a nested FabTheme.
sizeSmall / Regular / LargeDp40 / 56 / 96container sizes
extendedHeightDp56extended height
shapeSmall / Regular / LargeShapemedium / large / extraLargecorners
iconSizeRegular / LargeDp24 / 36icon sizes
elevationElevationLevelLevel3depth
softColors / solidColors / raisedColorsFabColors(container, content)M3 valuescolors per appearance for tone = Default

Accessibility​

  • Role button, with name = text when extended, else contentDescription.
  • The touch target is at least 48 (a Small FAB gets a margin).
  • Collapsing while scrolling doesn't change the accessible name.

4. Build steps​

  1. CamoFab (extended width animation, fallbacks), FabRenderer, and the DebugSkin renderer.
  2. Sample: an inbox with an extended "Compose" FAB that collapses on scroll (a scroll helper like the top bar's), placed above the navigation bar and snackbars.
  3. Tests: name when collapsed vs extended; the target size; the expand/collapse animation (golden); tone colors.

Done when

  • The inbox sample's FAB collapses and expands on scroll, and stays above the navigation bar and snackbars.

5. Edge cases​

CaseDecided behavior
Apple / Fluent / Carbon dialectsNo FAB in those systems. Their skins render a prominent circular (Carbon: square) button, and design guidance suggests a toolbar action instead. The component stays in core because every skin can draw a reasonable equivalent (ADR-23). Those skins ignore FabTheme.size and use their single size.
FAB menu (speed dial, M3 2025)Later.
RTLPlacement at bottom-end moves to the left. The icon doesn't mirror unless it's directional.
Hide on scrollvisible = rememberHideOnScroll(listState), or keep it visible and collapse it with expanded instead. A hidden FAB isn't focusable.
Changed in the M8 build (2026-11-01)
  • FabState carries the label (text) and expanded, and FabSlots only the icon. A FAB with a text is extended; collapsing it keeps its accessible name (text ?: contentDescription).
  • Core hides the FAB itself (visible = false: a scale and fade, then out of the tree and focus order), so a renderer only draws a visible one. A hidden FAB can't be focused, tapped or read.
  • FabTheme gains iconGap, extendedPadding and textStyle. FabStyle.colorsFor(state, theme) gives the appearance's colors for Tone.Default and the tone's family otherwise (Solid a strong fill, Soft a container fill, Raised a lifted surface with the tone's strong content).
  • Minimal draws it flat (ink fill, a hairline on Raised); Fluent draws a circular brand button with Level3 depth, since neither dialect has a FAB.

Implementation​

1. Why​

The FAB brings three Compose-specific pieces: animating between the extended and collapsed widths, hiding and showing with visible (ADR-30) while staying unfocusable when hidden, and reading the brand's size from FabTheme.size instead of a parameter (ADR-23).

2. Shape​

3. API​

@Composable
public fun CamoFab(
icon: @Composable () -> Unit,
contentDescription: String,
onClick: () -> Unit,
modifier: Modifier = Modifier,
text: String? = null,
expanded: Boolean = true,
visible: Boolean = true,
appearance: Appearance? = null, // null → FabTheme.defaultAppearance
tone: Tone = Tone.Default,
interactionSource: MutableInteractionSource? = null,
)
  • Visibility: AnimatedVisibility(visible, enter = scaleIn(initialScale = .6f) + fadeIn(), exit = scaleOut(targetScale = .6f) + fadeOut()) with durations from theme.motion. When hidden the FAB leaves composition, so it can't be focused or clicked.
  • Extended ↔ collapsed: the renderer puts the text in AnimatedVisibility(expanded, enter = expandHorizontally(), exit = shrinkHorizontally()) inside a Row(Modifier.animateContentSize()). The accessible name stays text ?: contentDescription in both states.
  • Size: style.size (FabSize.Small | Regular | Large) picks sizeSmall/Regular/Large and the matching shape and icon size. Skins with one size ignore it.
  • The behavior modifier: minimumInteractiveComponentSize()-equivalent (core's minimumTouchTarget()), clickable(role = Role.Button), semantics { contentDescription = text ?: contentDescription }.
  • Placement is app layout: Box(Modifier.fillMaxSize()) { … ; CamoFab(…, Modifier.align(Alignment.BottomEnd).padding(16.dp).navigationBarsPadding()) }.

4. Build steps​

  1. FabTheme / FabStyle (with size, defaultAppearance), CamoFab, the DebugSkin renderer.
  2. The inbox sample: an extended "Compose" FAB that collapses while scrolling (expanded = !listState.isScrollInProgress or the scroll-direction helper) and a variant that hides with visible = rememberHideOnScroll(listState).
  3. commonTest: name when collapsed and extended; visible = false removes the node; the 48 target on Small; tone colors.

Done when

  • The inbox FAB collapses, expands, hides and shows smoothly on Android, iOS, desktop and web, and is never focusable while hidden.

5. Edge cases​

CaseDecided behavior
visible toggles quickly while scrollingAnimatedVisibility reverses mid-animation; no queueing.
Reduced motionEnter/exit become instant (the provider's reduced CamoMotion).
A FAB over the navigation bar and a snackbarWrap content in CamoMessengerInsets(bottom = fabHeight + 16.dp) so snackbars sit above it.
Changed in the M8 build (2026-11-01)
  • The caller's modifier goes on the AnimatedVisibility wrapper (so Modifier.align from a Box works); the click, semantics and touch target go on the renderer's node inside it.
  • A collapsed extended FAB keeps its accessible name through semantics { contentDescription = text ?: contentDescription }.