Skip to main content

CamoTabs

Concept​

1. Why​

Tabs switch between related views at the same level ("Overview / Reviews / Specs"). CamoTabs is the tab bar only: the selected value in, selection changes out. The content below (a pager or a simple switch) stays the app's layout, with a small helper to keep a pager in sync. Material has primary and secondary tabs, Apple uses segmented controls or tab views, Fluent TabList, and Carbon Tabs.

2. Shape​

Material mapping preview: M3 primary tabs.

  • 48 tall (64 with icon and label), surface container.
  • The selected label is primary, and unselected onSurfaceVariant, in titleSmall.
  • A 3 dp primary indicator with rounded top, the width of the content.
  • A 1 dp outlineVariant divider below.

3. API​

Contract​

fun <T> CamoTabs(
selected: T,
onSelect: (T) -> Unit,
tabs: List<CamoTab<T>>,
scrollable: Boolean = false, // true → tabs keep their natural width and the row scrolls
appearance: Appearance? = null, // null → TabsTheme.defaultAppearance (skin default: Solid); Solid → prominent tabs (top-level views); Ghost → quiet tabs (sub-views inside a section)
)
data class CamoTab<T>(val value: T, val label: String? = null, val icon: Widget? = null,
val badge: Widget? = null, val contentDescription: String? = null, val enabled: Boolean = true)

// helper for the content: keeps a pager and the tab selection in sync (platform notes)

Building blocks (ADR-30): CamoTabsContainer(selectedIndex, scrollable, content: Slot) draws the row, the divider and the animated indicator (it measures its children to place the indicator), and CamoTabItem(tab, selected, onClick, position) draws one skin-styled tab with tab semantics ("Reviews, tab, 2 of 3"). Together they make custom tab bars (pill tabs inside a card, tabs with counters or custom content) that still look and behave like the brand's tabs.

State → renderer: TabsState(count, selectedIndex, scrollable, appearance, interactions). Slots: one TabSlot(label?, icon?, badge?) per tab.

Tokens used​

  • colors.surface, primary, onSurfaceVariant, outlineVariant
  • typography.titleSmall, icons 24
  • motion.durationMedium + easingEmphasized (the indicator slides between tabs)

Component theme​

theme.components.tabs: TabsTheme?. 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
defaultAppearanceAppearanceSolidthe appearance used when a call passes none (ADR-28: a brand's default variant)
height / heightWithIconDp48 / 64bar height
indicatorHeightDp3indicator thickness
indicatorWidthContent | TabContent (primary tabs)indicator width
labelStyleCamoTextStyletitleSmalllabels
minTabWidth (scrollable)Dp90scrollable tab width
showDividerBooleantruethe line below the bar
colorsTabsColors(container, selected, unselected, indicator, divider)surface, primary, onSurfaceVariant, primary, outlineVariantevery color it uses

Accessibility​

  • A tab list, with each tab a tab ("Reviews, tab, 2 of 3, selected").
  • Keyboard: arrows move focus and select; Home/End jump.
  • The content area should be labelled by the selected tab (the pager helper sets it).

4. Build steps​

  1. CamoTabs (fixed and scrollable, indicator animation, keyboard, semantics), TabsRenderer, and the DebugSkin renderer.
  2. The pager-sync helper (platform notes).
  3. Tests:
    • a tap selects;
    • the arrow keys;
    • the scrollable row keeps the selected tab visible;
    • announcements;
    • the indicator moves (golden).

Done when

  • A product screen with three tabs and a swipeable pager works by touch, swipe, keyboard and screen reader.

5. Edge cases​

CaseDecided behavior
Too many tabs for the widthUse scrollable = true. In fixed mode, labels ellipsize.
Icon-only tabsNeed contentDescription (debug assertion).
RTLThe tab order and the indicator animation mirror.
Tabs vs segmented controlTabs switch views. A segmented control switches a setting or filter inside a view.
Custom tab barsCamoTabsContainer + CamoTabItems (ADR-30). A tab item that isn't a CamoTabItem gets no indicator position; the container asserts in debug.
Changed in the M8 build (2026-11-01)
  • The renderer draws in two parts, the bar (Container: surface, divider and indicator around a row it is handed) and each tab (Tab). Core measures the tabs and animates the indicator; the renderer only paints TabsState.indicator (a start and width in pixels from the row's start), so the animation costs no recomposition or rebuild. TabSlots carries a handle (contentModifier / contentKey) the renderer puts on the node wrapping a tab's content, which is how the indicator can be as wide as the content.
  • TabsTheme has solidColors and ghostColors instead of one colors (Solid is the prominent bar, Ghost the quiet one), and gains iconSize, iconGap and tabPadding. indicatorWidth is the IndicatorWidth enum (Content | Tab).
  • CamoTabs and the container take an optional indicatorPosition (Kotlin) / position (Flutter): a fractional tab index the indicator follows instead of animating, which is how it tracks a swipe. The container also takes appearance and enabled.
  • The pager sync is a controller that holds the truth: the pager's current page is the selected tab, a tap animates the pager, and the sync's position feeds the indicator. The app keeps no separate selected state.
  • A selection that is not among the tabs draws no indicator; a disabled bar or tab ignores taps and keys.
  • Minimal: a hairline under the bar and a 2 px ink indicator as wide as the tab. Fluent: no divider and a 2 px rounded brand indicator as wide as the content.

Implementation​

1. Why​

A tab bar: selection in, selection out, with an animated indicator. Compose's TabRow is Material, so core builds CamoTabsContainer (measures its tabs and animates the indicator) and CamoTabItem (one tab), which are also the public building blocks (ADR-30), plus a helper that syncs tabs with a HorizontalPager.

2. Shape​

3. API​

@Composable
public fun <T> CamoTabs(
selected: T,
onSelect: (T) -> Unit,
tabs: List<CamoTab<T>>,
modifier: Modifier = Modifier,
scrollable: Boolean = false,
appearance: Appearance? = null, // null → TabsTheme.defaultAppearance
)

// building blocks (ADR-30)
@Composable public fun CamoTabsContainer(selectedIndex: Int, modifier: Modifier = Modifier, scrollable: Boolean = false,
content: @Composable CamoTabsScope.() -> Unit)
@Composable public fun <T> CamoTabsScope.CamoTabItem(tab: CamoTab<T>, selected: Boolean, onClick: () -> Unit,
position: ItemPosition, modifier: Modifier = Modifier, content: (@Composable () -> Unit)? = null)

// pager sync
@Composable public fun <T> rememberCamoTabsPagerSync(pagerState: PagerState, tabs: List<CamoTab<T>>): CamoTabsPagerSync<T>
  • Indicator: each CamoTabItem reports its bounds through CamoTabsScope (Modifier.onPlaced); the container animates the indicator's offset and width with animateDpAsState, content width or tab width per style.indicatorWidth, and draws it in drawWithContent. During a pager swipe, the sync helper interpolates the indicator with pagerState.currentPageOffsetFraction.
  • Scrollable: Modifier.horizontalScroll(scrollState), and the selected tab is scrolled into view (bringIntoViewRequester).
  • Semantics: container selectableGroup(); each item selectable(selected, role = Role.Tab) with the position, so TalkBack reads "Reviews, tab, 2 of 3, selected". Arrow keys move between tabs (roving focus) and select.
  • Pager sync: tapping a tab calls pagerState.animateScrollToPage; settling on a page calls onSelect — snapshotFlow { pagerState.settledPage }.

4. Build steps​

  1. CamoTab, TabsTheme / Style, the building blocks, CamoTabs built from them, the DebugSkin renderer.
  2. rememberCamoTabsPagerSync on foundation's HorizontalPager (multiplatform).
  3. UI tests: tap selects; the indicator moves; scrollable brings the selection into view; the pager and tabs stay in sync both ways; custom content tabs keep tab semantics.

Done when

  • A product page (fixed tabs + pager) and a category bar (scrollable) work by touch, keyboard and screen reader on all targets.

5. Edge cases​

CaseDecided behavior
selected not in tabsNo indicator; debug log.
A tab that isn't a CamoTabItem inside the containerIt gets no indicator bounds; a debug assertion.
RTLTabs and indicator mirror; the pager mirrors on its own.
Changed in the M8 build (2026-11-01)
  • The indicator's bounds come from onGloballyPositioned on each item (and on the content wrapper the renderer marks), kept in a registry on the container; positionInParent mirrors on its own in RTL, since the indicator is drawn in the row's physical coordinates.
  • The first placement snaps; later ones animate with animateFloatAsState, read in the draw phase.
  • rememberCamoTabsPagerSync(pagerState, tabs) returns a CamoTabsPagerSync with selected, onSelect and position; pass them to CamoTabs(selected, onSelect, tabs, indicatorPosition = position).
  • The scrollable row centers the selected tab with scrollState.animateScrollTo, using the registry's bounds and the viewport width.