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 contentonPrimaryContainer, atlevel3. 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/onContainerfor Soft,strong/onStrongfor 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.
| Field | Type | Material default | What it's for |
|---|---|---|---|
defaultAppearance | Appearance | Soft | the appearance used when a call passes none (ADR-28: a brand's default variant) |
size | FabSize (Small | Regular | Large) | Regular | which 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 / Large | Dp | 40 / 56 / 96 | container sizes |
extendedHeight | Dp | 56 | extended height |
shapeSmall / Regular / Large | Shape | medium / large / extraLarge | corners |
iconSizeRegular / Large | Dp | 24 / 36 | icon sizes |
elevation | ElevationLevel | Level3 | depth |
softColors / solidColors / raisedColors | FabColors(container, content) | M3 values | colors per appearance for tone = Default |
Accessibility
- Role button, with name =
textwhen extended, elsecontentDescription. - 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
CamoFab(extended width animation, fallbacks),FabRenderer, and the DebugSkin renderer.- 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.
- 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
| Case | Decided behavior |
|---|---|
| Apple / Fluent / Carbon dialects | No 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. |
| RTL | Placement at bottom-end moves to the left. The icon doesn't mirror unless it's directional. |
| Hide on scroll | visible = rememberHideOnScroll(listState), or keep it visible and collapse it with expanded instead. A hidden FAB isn't focusable. |
FabStatecarries the label (text) andexpanded, andFabSlotsonly the icon. A FAB with atextis 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. FabThemegainsiconGap,extendedPaddingandtextStyle.FabStyle.colorsFor(state, theme)gives the appearance's colors forTone.Defaultand 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
Level3depth, 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 fromtheme.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 aRow(Modifier.animateContentSize()). The accessible name staystext ?: contentDescriptionin both states. - Size:
style.size(FabSize.Small | Regular | Large) pickssizeSmall/Regular/Largeand the matching shape and icon size. Skins with one size ignore it. - The behavior modifier:
minimumInteractiveComponentSize()-equivalent (core'sminimumTouchTarget()),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
FabTheme/FabStyle(withsize,defaultAppearance),CamoFab, the DebugSkin renderer.- The inbox sample: an extended "Compose" FAB that collapses while scrolling (
expanded = !listState.isScrollInProgressor the scroll-direction helper) and a variant that hides withvisible = rememberHideOnScroll(listState). commonTest: name when collapsed and extended;visible = falseremoves the node; the 48 target onSmall; 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
| Case | Decided behavior |
|---|---|
visible toggles quickly while scrolling | AnimatedVisibility reverses mid-animation; no queueing. |
| Reduced motion | Enter/exit become instant (the provider's reduced CamoMotion). |
| A FAB over the navigation bar and a snackbar | Wrap content in CamoMessengerInsets(bottom = fabHeight + 16.dp) so snackbars sit above it. |
- The caller's
modifiergoes on theAnimatedVisibilitywrapper (soModifier.alignfrom aBoxworks); 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 }.