CamoCarousel
Concept
1. Why
A carousel shows a horizontal strip of items you swipe or step through: a photo gallery, featured cards, onboarding pages (Material's carousel, Fluent's Carousel, page views). Items can peek at the edges. It is not tabs and not a pager for navigation (that is CamoTabs with a pager).
2. Shape
Split of duties
| Core | Skin (renderer) |
|---|---|
the paging and snapping, the page state (controlled or remembered), peek and item width, previous and next buttons on pointer devices, keyboard, semantics ("item 2 of 5"), optional page indicator through CamoPagination | the container, the previous and next buttons, the indicator look, the item mask and spacing |
Material mapping preview: the M3 carousel (multi-browse, uncontained, hero).
- Items
shapes.extraLarge, 16 dp gaps, a hero item at 3x the small ones.
3. API
Contract
fun <T> CamoCarousel(
items: List<T>,
state: CarouselState = rememberCarouselState(), // page, scrollToPage(i)
itemKey: (T) -> Any,
layout: CarouselLayout = Paged, // Paged (one at a time) | Peek(fraction) | MultiBrowse
showButtons: Boolean = Auto, // pointer devices
showIndicator: Boolean = true,
caption: String,
content: @Composable (T) -> Unit,
)
State → renderer: CarouselState(page, pageCount, hasPrevious, hasNext); the renderer draws the container and NavButton(direction, enabled, interaction); the item content is the app's. The indicator is CamoPagination's page-control form.
Tokens used
colors.surface,onSurface,scrimshapes.extraLarge(item mask),spacing.mgapmotion.durationMedium(snap)
Component theme
theme.components.carousel. 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 |
|---|---|---|---|
itemShape | Shape | shapes.extraLarge | the mask |
itemSpacing | Dp | 12 | between items |
peek | Dp | 24 | the next item showing at the edge |
buttonStyle | ButtonColors | scrim fill | previous and next |
strings | CarouselStrings | English | "previous", "next", "item 2 of 5" |
Accessibility
- A region named by
caption; each item announces "item 2 of 5"; the previous and next buttons are buttons. - Left and Right (reading direction) move one item; Home and End jump. Off-screen items are not focusable.
- Reduced motion: the snap is instant.
4. Build steps
CarouselState, layouts,CarouselTheme/Style, state, renderer, theCamoSkinfield.CamoCarousel, the DebugSkin renderer.- Tests: snap and page state, peek, buttons, keys, RTL, semantics.
Done when
- The admin sample's image gallery pages by swipe, buttons and keys.
5. Edge cases
| Case | Decided behavior |
|---|---|
| Case | Decided behavior |
| --- | --- |
| One item | No buttons or indicator. |
| Many items | Lazy: only the visible ones compose. |
| RTL | The strip and the buttons mirror. |
- The renderer has three parts:
Container,Item(each item's mask) andButton(previous and next); the page dots areCamoPagination's dots form.CarouselThemehasitemShape,itemSpacing,peek,buttonSize, the two icons andCarouselColors(buttonContainer, buttonContent). The layouts arePagedandPeek; multi-browse and hero layouts are not built. - The buttons show on pointer devices by default (
showButtons) and flip in right-to-left layouts. Left and Right (reading direction), Home and End step and jump; each item announces "item 2 of 5" and the previous and next buttons are named. There is no auto-play. A single item has no buttons or dots. - Position is the platform's own pager state, so the app can read and move it: no new state type.
- Auto-play is not in v0.1 (an accessibility hazard); say if you want it with a pause control.
Implementation
1. Why
HorizontalPager from Compose Foundation, with a PageSize for peek, rememberPagerState; the state wraps it.
2. Shape
3. API
@Composable public fun <T> CamoCarousel(items: List<T>, itemKey: (T) -> Any, caption: String, modifier: Modifier = Modifier,
state: CarouselState = rememberCarouselState(), layout: CarouselLayout = CarouselLayout.Paged,
showButtons: Boolean? = null, showIndicator: Boolean = true, content: @Composable (T) -> Unit)
CarouselStateholds thePagerState;scrollToPageandanimateScrollToPageare suspend functions.- Semantics: the pager's
collectionInfo, each pagecollectionItemInfo; buttons useRole.Button.
4. Build steps
- State, pager, buttons, indicator, renderer.
- Tests: page state, keys, semantics, RTL.
Done when
- Works by touch, mouse, keyboard and screen reader on all targets.
5. Edge cases
| Case | Decided behavior |
|---|---|
| Drag on desktop | Mouse drag scrolls (a scroll behavior with the mouse as a drag device). |
stateis Compose'sPagerState(rememberPagerState { items.size }by default); items are aHorizontalPagerwith the peek ascontentPadding.
- None specific.