CamoPagination
Concept
1. Why
Pagination moves through pages of a long result: a table's pages, search results (Material's none, Fluent and Carbon's Pagination, Apple's page control). It has two forms: numbered (previous, 1 2 3 … 9, next) and page control (dots, for carousels and onboarding).
2. Shape
Split of duties
| Core | Skin (renderer) |
|---|---|
the page model (count, current, siblings, the ellipsis rule), the keys (Left and Right, Home, End), onPageChange, semantics (a navigation landmark, "page 3, current"), compact mode by width | the page button look (current, hover), the arrows, the dots, spacing |
Material mapping preview: the M3 has no pagination; the dots follow the carousel indicator.
- 40 dp buttons, the current page
secondaryContainer.
3. API
Contract
fun CamoPagination(
pageCount: Int,
page: Int, // zero-based
onPageChange: (Int) -> Unit,
variant: PaginationVariant = Numbered, // Numbered | Compact ("Page 3 of 9") | Dots
siblings: Int = 1, // pages next to the current one
enabled: Boolean = true,
label: String = "Pagination",
)
State → renderer: PaginationState(pageCount, page, variant); PageButtonState(index, current, enabled, interaction) and PageArrowState(direction, enabled, interaction) for each part; the ellipsis is PageGapState. Slots: none.
Tokens used
colors.secondaryContainer,onSurface,onSurfaceVarianttypography.labelLarge;shapes.small;spacing.xs
Component theme
theme.components.pagination. 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 |
|---|---|---|---|
buttonSize | Dp | 40 | |
shape | Shape | shapes.small | |
dotSize | Dp | 8 | the dots form |
previousIcon / nextIcon | IconSource | chevrons | |
colors | PaginationColors(current, text, dot, activeDot) | M3 values | every color it uses |
strings | PaginationStrings | English | "Previous page", "Next page", "Page 3 of 9", "current" |
Accessibility
- A navigation landmark named
label; page buttons "Page 3" and the current one "Page 3, current page" (selected). - One Tab stop; Left and Right move between pages and select, Home and End jump to the first and last.
- Dots announce "Page 3 of 9" as one adjustable value.
4. Build steps
- The page model (the ellipsis rule as a pure function), theme, state, renderer, the
CamoSkinfield. CamoPagination, the DebugSkin renderer.- Tests: the page model for many sizes, keys, compact and dots, semantics.
Done when
- The admin table pages with it.
5. Edge cases
| Case | Decided behavior |
|---|---|
| Case | Decided behavior |
| --- | --- |
| One page | Renders nothing (or a disabled single page when alwaysShow). |
| Narrow window | Numbered becomes Compact by width. |
| RTL | Arrows mirror. |
- The renderer has seven parts:
Container,Button,Arrow,Gap,DotandSummary, withPageButtonState,PageArrowStateandPageDotState;PaginationColors(currentContainer, currentContent, content, dot, activeDot). - The numbered form's items come from one pure function (
pageItems): always the first and last page, the siblings around the current one, and gaps, with a fixed length of2 * siblings + 5once there are more pages than that. - The arrow keys move focus between the parts without selecting (Enter or Space picks), unlike the segmented control: changing the page on each arrow would shift the items under the focus. Changing to Compact on a narrow window is the app's choice (
LayoutBuilderor the window size): core stays free of intrinsic-size traps. Not built:alwaysShow, built-in strings.
- A page-size selector and a "go to page" field are the app's (
CamoSelect,CamoTextField); say if you want them built in.
Implementation
1. Why
A Row of renderer-drawn parts with rememberRovingFocus; selectable for the current page.
2. Shape
3. API
@Composable public fun CamoPagination(pageCount: Int, page: Int, onPageChange: (Int) -> Unit, modifier: Modifier = Modifier,
variant: PaginationVariant = PaginationVariant.Numbered, siblings: Int = 1, enabled: Boolean = true,
label: String = "Pagination")
internal fun pageItems(pageCount, page, siblings): List<PageItem>is pure and tested alone.
4. Build steps
pageItems, row, keys, renderer.- Tests:
pageItemsfor edges, keys, semantics.
Done when
- Works by touch, mouse, keyboard and screen reader on all targets.
5. Edge cases
| Case | Decided behavior |
|---|---|
| Page count change | A page beyond the new count clamps and reports onPageChange once. |
- Parts use
rovingFocusItem(…, onSelect = {}),clickableandminimumTouchTarget; the arrows are disabled at the ends.
- None specific.