CamoSkeleton
Concept
1. Why
A skeleton is a gray placeholder in the shape of content that hasn't loaded yet: text lines, an avatar circle, an image block. It tells the user what's coming and keeps the layout from jumping. CamoPagedList uses it for loading rows, and apps use it on any loading screen. It replaces the hand-written shimmer widgets each app carries today.
2. Shape
Material mapping preview: Material has no skeleton component. The Material skin uses surfaceContainerHighest blocks with a sweeping surfaceContainerLow highlight. See Material Skin.
3. API
Contract
fun CamoSkeleton(
width: Dp? = null, // null → fill the available width
height: Dp,
shape: ShapeRole = Small,
)
fun CamoSkeleton.text(lines: Int = 1, style: CamoTextStyle = typography.bodyMedium, lastLineFraction: Float = 0.6f)
fun CamoSkeleton.circle(size: Dp)
fun CamoSkeleton.listItem(lines: Int = 2, leading: SkeletonLeading = Circle) // Circle | Square | None; matches CamoListItem proportions
fun CamoSkeletonGroup(content: Slot) // one shared animation phase for all skeletons inside
| Function | What it's for |
|---|---|
CamoSkeleton | a block (an image, a button, a card) |
.text | text lines at the height of a text style, the last line shorter |
.circle | an avatar |
.listItem | a whole list row, sized from ListItemTheme, so it lines up with the real rows |
CamoSkeletonGroup | keeps the shimmer in sync across a screen (otherwise each block would animate on its own) |
State → renderer: SkeletonState(shape, animationPhase). Slots: none.
Tokens used
colors.surfaceContainerHigh(base),surfaceContainerLowest(highlight)shapes.<shape>,shapes.full(circle)motion.durationLong× 3 for one shimmer cycle
Component theme
theme.components.skeleton: SkeletonTheme?. 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 |
|---|---|---|---|
animation | SkeletonAnimation (Shimmer | Pulse | None) | Shimmer | how placeholders move (ADR-28: a brand choice) |
baseColor / highlightColor | Color | surfaceContainerHighest / surfaceContainerLow | the block and the moving highlight |
cycleDuration | Duration | 1500 ms | one shimmer or pulse cycle |
textLineGap | Dp | 8 | space between text lines |
Accessibility
- Skeletons are hidden from screen readers. The container that shows them exposes one "Loading" state (a live region), as
CamoPagedListdoes. - Reduced motion: the animation becomes
None(static blocks). - The contrast between blocks and background is low on purpose. Skeletons are decoration, not content.
4. Build steps
CamoSkeletonand its helpers in core, the shared phase inCamoSkeletonGroup, andSkeletonRenderer(DebugSkin: plain gray blocks)..listItem()readsListItemThemeheights and paddings.- Tests:
- sizes and shapes;
.text(3)draws 3 lines with a shorter last line;- reduced motion is static;
- no semantics nodes;
- blocks in a group share one phase.
Done when
- A skeleton list and a skeleton profile header render in light and dark, animated and with reduced motion, and line up with the real content that replaces them.
5. Edge cases
| Case | Decided behavior |
|---|---|
| Many skeletons on screen | One animation clock per CamoSkeletonGroup (and one implicit group per CamoPagedList), not one per block. |
| Dark theme | The same roles give a subtle dark shimmer. No separate colors. |
| Font scale 200% | .text lines grow with the style's line height, like the real text will. |
| RTL | The shimmer sweeps from right to left. |
SkeletonStatecarries the resolved shape, the animation (alreadyNoneunder reduced motion) and the shared phase, read while painting. Core paints for the skins: KotlinModifier.drawSkeleton, FlutterCamoSkeletonPaint.- A text line is a block
lineHeight − textLineGaptall inside a line of the style's line height, so lines match the real text. - Defaults: Minimal pulses, Fluent shimmers.
Implementation
1. Why
Skeleton placeholders need a cheap shared animation. In Compose that's one InfiniteTransition per CamoSkeletonGroup, a Brush.linearGradient moved by it, and drawWithCache so blocks don't allocate per frame.
2. Shape
3. API
@Composable public fun CamoSkeleton(height: Dp, modifier: Modifier = Modifier, width: Dp? = null, shape: ShapeRole = ShapeRole.Small)
@Composable public fun CamoSkeletonText(modifier: Modifier = Modifier, lines: Int = 1,
style: TextStyle = Camouflage.typography.bodyMedium, lastLineFraction: Float = 0.6f)
@Composable public fun CamoSkeletonCircle(size: Dp, modifier: Modifier = Modifier)
@Composable public fun CamoSkeletonListItem(modifier: Modifier = Modifier, lines: Int = 2, leading: SkeletonLeading = SkeletonLeading.Circle)
@Composable public fun CamoSkeletonGroup(content: @Composable () -> Unit)
(Kotlin names the base's CamoSkeleton.text/.circle/.listItem as top-level functions, the Compose convention.)
- Phase:
CamoSkeletonGroupprovidesLocalSkeletonPhasefromrememberInfiniteTransition().animateFloat(0f, 1f, infiniteRepeatable(tween(style.cycleDuration))). A skeleton outside a group creates its own. - Drawing:
Shimmer→drawWithCache { onDrawBehind { drawRect(base); drawRect(brush translated by phase * width) } }clipped to the shape;Pulse→ alpha between 0.5 and 1;None→ a static block. Reduced motion forcesNone. - Text lines: each line's height is the style's
lineHeightconverted withLocalDensity, so lines match the real text at any font scale. clearAndSetSemantics {}on every block.
4. Build steps
SkeletonTheme/Style, the composables, the DebugSkin renderer (static gray).commonTest: sizes;lines = 3with a shorter last line; reduced motion is static; no semantics; blocks in a group read the same phase.
Done when
- A skeleton list and profile header match the real layout on every target, animated and with reduced motion.
5. Edge cases
| Case | Decided behavior |
|---|---|
A skeleton in a LazyColumn item | The list's group phase is shared across items (the provider sits outside the list). |
| RTL | The brush moves right to left. |