CamoRating
Concept
1. Why
A rating shows or collects a score on a small scale, usually stars (Fluent's Rating, Apple's rating controls, Material's rating in lists). It can be read-only (an average) or interactive, with whole or half steps.
2. Shape
Split of duties
| Core | Skin (renderer) |
|---|---|
| the value, steps, pointer and keyboard (arrows, Home, End, digits), hover preview, semantics (an adjustable value), read-only and disabled | the icon (star, heart), filled, half and empty looks, size, gap, colors |
Material mapping preview: the M3 has none; Material apps draw stars.
- 24 dp stars,
primaryfilled,outlineempty.
3. API
Contract
fun CamoRating(
value: Float, // 0..max, in steps
onValueChange: ((Float) -> Unit)? = null, // null: read-only
max: Int = 5,
step: RatingStep = Whole, // Whole | Half
size: RatingSize = Medium,
enabled: Boolean = true,
label: String, // names it: "Quality"
)
State → renderer: RatingState(value, max, step, hoverValue, interactive, enabled); the renderer draws max icons; RatingItemState(fill: 0f..1f, interaction) gives each its fill.
Tokens used
colors.primary(filled),outline,onSurfaceVariant- icon size 16 / 24 / 32,
spacing.xs
Component theme
theme.components.rating. 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 |
|---|---|---|---|
icon | IconSource | star | filled and empty (outline) variants |
iconSize | Dp by size | 16 / 24 / 32 | |
gap | Dp | 4 | |
colors | RatingColors(filled, empty, hover, disabled) | M3 values | every color it uses |
strings | RatingStrings | English | "3 of 5 stars" |
Accessibility
- Read-only: announces "Quality, 3.5 of 5 stars". Interactive: an adjustable value (a slider role): Up, Right and swipe-up increase by a step, Down, Left and swipe-down decrease, Home and End set the ends; screen readers get increment and decrement actions.
- One Tab stop; the hover preview is visual only.
4. Build steps
RatingStep,RatingTheme/Style, state, renderer, theCamoSkinfield.CamoRating, the DebugSkin renderer.- Tests: steps, tap and drag, keys, half values, read-only, semantics.
Done when
- The sample's review form and the table's average column work.
5. Edge cases
| Case | Decided behavior |
|---|---|
| Case | Decided behavior |
| --- | --- |
| Tapping the current value | Does not clear it (allowClear = true makes it). |
| RTL | Fills from the right. |
RatingColors(filled, empty, hover, disabled); there is one icon: empty icons are the same icon in the empty color and half icons clip the filled one (so a skin needs a filled glyph only). Sizes aresmallSize,mediumSizeandlargeSize.- The renderer draws
maxicons fromRatingState(value, hover value, interaction or focus); each icon plus its gap must share the width evenly, because core maps the pointer position to a value from the width. The hover preview is mouse only. - Semantics: read-only announces "3.5 of 5 stars"; interactive adds the adjustable actions (Kotlin
setProgress, Flutter increase and decrease). Not built:allowClearand built-in strings.
- A count next to the stars ("4.5 (212)") is the app's
CamoText; say if you want it built in.
Implementation
1. Why
Modifier.draggable/pointerInput over the row of icons; Modifier.semantics { setProgress } and progressBarRangeInfo for the adjustable role.
2. Shape
3. API
@Composable public fun CamoRating(value: Float, label: String, modifier: Modifier = Modifier,
onValueChange: ((Float) -> Unit)? = null, max: Int = 5, step: RatingStep = RatingStep.Whole,
size: RatingSize = RatingSize.Medium, enabled: Boolean = true)
4. Build steps
- Interaction, semantics, renderer.
- Tests: taps, drag, keys, semantics.
Done when
- Works by touch, mouse, keyboard and screen reader on all targets.
5. Edge cases
| Case | Decided behavior |
|---|---|
| Half steps | The pointer position inside an icon picks the half. |
- Pointer: tap and horizontal drag from
pointerInput; keys fromonKeyEvent;ProgressBarRangeInfocarries the value.
- None specific.