CamoStepper
Concept
1. Why
A number input with − and + buttons: cart quantities, guest counts, passengers. Apple has a Stepper, Fluent a SpinButton, Carbon a number input; Material has none, so apps build it by hand. Camouflage makes it one controlled component (ADR-35).
2. Shape
Material mapping preview: Material has no stepper; the Material skin draws Inline with outlined icon buttons around a titleMedium value. See Material Skin.
3. API
Contract
fun CamoStepper(
value: Int, // whole numbers; the decimal overload is below
onValueChange: (Int) -> Unit,
range: IntRange = 0..Int.MAX_VALUE,
step: Int = 1,
label: String? = null, // accessible name ("Quantity"), shown if the skin draws labels
allowTyping: Boolean = true, // the value is an editable number field
valueText: ((Int) -> String)? = null, // e.g. { "$it nights" }
error: String? = null,
enabled: Boolean = true,
)
// decimals: weights, prices, doses
fun CamoStepper(
value: CamoDecimal, // fixed-point, never a binary float (see §5)
onValueChange: (CamoDecimal) -> Unit,
range: ClosedRange<CamoDecimal>,
step: CamoDecimal, // e.g. CamoDecimal("0.5"), CamoDecimal("0.25")
decimals: Int, // shown and typed digits after the separator
/* … the same other parameters … */
)
// inside a form: CamoStepperFormField(key, initialValue, rules, …)
- The − button disables at
range.first, the + button atrange.last. - Press and hold repeats: after 400 ms, then faster, up to 10 changes per second.
- With
allowTyping, the value is a digits-only text field; the typed value is clamped torangeand snapped tostepwhen focus leaves.
State → renderer (M5 build): StepperState(valueText, enabled, error: Boolean, focused, decrease: StepperButton, increase: StepperButton). Each StepperButton(enabled, interaction, behavior) carries core's behavior (click, hold-to-repeat, label) and the renderer draws the button, so a Split layout can make ▲ ▼ half the field's height. Slots: StepperSlots(input): core's editable field.
Tokens used
colors.outline(buttons, field),onSurface, the disabled alphas,errortypography.titleMedium(value),shapes.small,spacing.s
Component theme
theme.components.stepper: StepperTheme?. Every field is nullable in the theme (Material defaults shown).
| Field | Type | Material default | What it's for |
|---|---|---|---|
layout | Inline | Split | Inline | − value + in a row, or a field with ▲▼ at the end (ADR-28; Fluent and Carbon: Split) |
buttonAppearance | Appearance | Outline | the − and + buttons |
valueMinWidth | Dp | 40 | keeps the layout from jumping between 9 and 10 |
decreaseIcon / increaseIcon | IconSource? | the skin's − / + | a brand's own icons |
colors | StepperColors(button, value, field, error) | as in Tokens used | every color it uses |
Accessibility
- Three stops: a "Decrease quantity" button, the value ("Quantity, 2", an editable field when
allowTyping), and an "Increase quantity" button. Each change is announced politely ("3"). Buttons at a limit are announced as dimmed. - On the focused value, keyboard Up/Down change it by
step, PageUp/PageDown by 10 steps, Home/End to the ends. - Value changes are announced politely.
4. Build steps
CamoStepperwith clamping, stepping, hold-to-repeat, typing,StepperRenderer, the DebugSkin renderer.CamoStepperFormField.- Sample: a cart line, a guest counter with
valueText, aSplitstepper in a form. - Tests: limits disable buttons; hold repeats; typing clamps and snaps on blur; the three screen-reader stops and the change announcement; decimal steps never drift (0.1 × 3 is exactly 0.3).
Done when
- The three samples work by touch, keyboard and screen reader on every platform.
5. Edge cases
| Case | Decided behavior |
|---|---|
| Decimal values | CamoDecimal is core's small fixed-point type on both platforms: an integer of units plus a scale (12.50 = 1250 with scale 2), with parsing, formatting, add/subtract and compare. No dependency, and steps never drift. Apps convert to their own money or quantity types at the edge. The value is shown with the locale's decimal separator; typing accepts both . and ,. |
| Typed value empty on blur | Restores the last valid value. |
range changes so value is outside | The component shows the value and flags it as out of range (error semantics); the app decides whether to clamp. |
Implementation
1. Why
A quantity control. Compose specifics: hold-to-repeat with a coroutine, one adjustable semantics node (the buttons hidden from traversal), and an optional digits-only field that clamps on blur.
2. Shape
3. API
@Composable
public fun CamoStepper(
value: Int, onValueChange: (Int) -> Unit, modifier: Modifier = Modifier,
range: IntRange = 0..Int.MAX_VALUE, step: Int = 1, label: String? = null,
allowTyping: Boolean = true, valueText: ((Int) -> String)? = null, error: String? = null, enabled: Boolean = true,
)
@Composable
public fun CamoStepper( // decimals
value: CamoDecimal, onValueChange: (CamoDecimal) -> Unit, range: ClosedRange<CamoDecimal>, step: CamoDecimal,
decimals: Int, modifier: Modifier = Modifier, /* … the same other parameters … */
)
@Immutable public data class CamoDecimal(val unscaled: Long, val scale: Int) : Comparable<CamoDecimal> {
public constructor(text: String) // "12.50" → (1250, 2)
public operator fun plus(o: CamoDecimal): CamoDecimal; public operator fun minus(o: CamoDecimal): CamoDecimal
public fun format(locale: String): String // locale decimal separator
}
- Hold to repeat:
pointerInput { awaitEachGesture { … } }on each button: after the first change, acoroutineScope.launchwaits 400 ms, then repeats with a delay that shrinks to 100 ms, until release; each tick callsonValueChangewith the latest value (rememberUpdatedState). - Semantics: three stops. The − and +
CamoIconButtons are normal buttons ("Decrease quantity" / "Increase quantity", disabled at the limits); the value is a text node (or the editable field) withcontentDescription = labelandliveRegion = LiveRegionMode.Polite, so each change is announced. Keyboard Up/Down/PageUp/PageDown/Home/End work on the focused value. - Typing: a digits-only
BasicTextFieldforInt(a digits + one separator filter forCamoDecimal, accepting.and,); on focus loss the text is parsed, clamped torange, snapped tostep, andonValueChangeis called if it differs.
4. Build steps
CamoStepper,StepperTheme/Style, the DebugSkin renderer, the form field.- UI tests: limits disable; hold repeats and stops on release; typing clamps on blur; three semantics stops with the value announced; decimal steps never drift.
Done when
- Cart, guest-counter and split samples work on all four targets.
5. Edge cases
| Case | Decided behavior |
|---|---|
| Recomposition during hold | The repeat reads the latest value through rememberUpdatedState, so a controlled value that the app clamps stops the repeat. |