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),
surfacecontainer. - The selected label is
primary, and unselectedonSurfaceVariant, intitleSmall. - A 3 dp
primaryindicator with rounded top, the width of the content. - A 1 dp
outlineVariantdivider 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,outlineVarianttypography.titleSmall, icons 24motion.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.
| Field | Type | Material default | What it's for |
|---|---|---|---|
defaultAppearance | Appearance | Solid | the appearance used when a call passes none (ADR-28: a brand's default variant) |
height / heightWithIcon | Dp | 48 / 64 | bar height |
indicatorHeight | Dp | 3 | indicator thickness |
indicatorWidth | Content | Tab | Content (primary tabs) | indicator width |
labelStyle | CamoTextStyle | titleSmall | labels |
minTabWidth (scrollable) | Dp | 90 | scrollable tab width |
showDivider | Boolean | true | the line below the bar |
colors | TabsColors(container, selected, unselected, indicator, divider) | surface, primary, onSurfaceVariant, primary, outlineVariant | every 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
CamoTabs(fixed and scrollable, indicator animation, keyboard, semantics),TabsRenderer, and the DebugSkin renderer.- The pager-sync helper (platform notes).
- 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
| Case | Decided behavior |
|---|---|
| Too many tabs for the width | Use scrollable = true. In fixed mode, labels ellipsize. |
| Icon-only tabs | Need contentDescription (debug assertion). |
| RTL | The tab order and the indicator animation mirror. |
| Tabs vs segmented control | Tabs switch views. A segmented control switches a setting or filter inside a view. |
| Custom tab bars | CamoTabsContainer + CamoTabItems (ADR-30). A tab item that isn't a CamoTabItem gets no indicator position; the container asserts in debug. |
- 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 paintsTabsState.indicator(a start and width in pixels from the row's start), so the animation costs no recomposition or rebuild.TabSlotscarries 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. TabsThemehassolidColorsandghostColorsinstead of onecolors(Solid is the prominent bar, Ghost the quiet one), and gainsiconSize,iconGapandtabPadding.indicatorWidthis theIndicatorWidthenum (Content|Tab).CamoTabsand the container take an optionalindicatorPosition(Kotlin) /position(Flutter): a fractional tab index the indicator follows instead of animating, which is how it tracks a swipe. The container also takesappearanceandenabled.- 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
CamoTabItemreports its bounds throughCamoTabsScope(Modifier.onPlaced); the container animates the indicator's offset and width withanimateDpAsState, content width or tab width perstyle.indicatorWidth, and draws it indrawWithContent. During a pager swipe, the sync helper interpolates the indicator withpagerState.currentPageOffsetFraction. - Scrollable:
Modifier.horizontalScroll(scrollState), and the selected tab is scrolled into view (bringIntoViewRequester). - Semantics: container
selectableGroup(); each itemselectable(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 callsonSelect—snapshotFlow { pagerState.settledPage }.
4. Build steps
CamoTab,TabsTheme/Style, the building blocks,CamoTabsbuilt from them, the DebugSkin renderer.rememberCamoTabsPagerSyncon foundation'sHorizontalPager(multiplatform).- 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
| Case | Decided behavior |
|---|---|
selected not in tabs | No indicator; debug log. |
A tab that isn't a CamoTabItem inside the container | It gets no indicator bounds; a debug assertion. |
| RTL | Tabs and indicator mirror; the pager mirrors on its own. |
- The indicator's bounds come from
onGloballyPositionedon each item (and on the content wrapper the renderer marks), kept in a registry on the container;positionInParentmirrors 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 aCamoTabsPagerSyncwithselected,onSelectandposition; pass them toCamoTabs(selected, onSelect, tabs, indicatorPosition = position).- The scrollable row centers the selected tab with
scrollState.animateScrollTo, using the registry's bounds and the viewport width.