Skip to main content

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
FunctionWhat it's for
CamoSkeletona block (an image, a button, a card)
.texttext lines at the height of a text style, the last line shorter
.circlean avatar
.listItema whole list row, sized from ListItemTheme, so it lines up with the real rows
CamoSkeletonGroupkeeps 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.

FieldTypeMaterial defaultWhat it's for
animationSkeletonAnimation (Shimmer | Pulse | None)Shimmerhow placeholders move (ADR-28: a brand choice)
baseColor / highlightColorColorsurfaceContainerHighest / surfaceContainerLowthe block and the moving highlight
cycleDurationDuration1500 msone shimmer or pulse cycle
textLineGapDp8space between text lines

Accessibility​

  • Skeletons are hidden from screen readers. The container that shows them exposes one "Loading" state (a live region), as CamoPagedList does.
  • 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​

  1. CamoSkeleton and its helpers in core, the shared phase in CamoSkeletonGroup, and SkeletonRenderer (DebugSkin: plain gray blocks).
  2. .listItem() reads ListItemTheme heights and paddings.
  3. 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​

CaseDecided behavior
Many skeletons on screenOne animation clock per CamoSkeletonGroup (and one implicit group per CamoPagedList), not one per block.
Dark themeThe 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.
RTLThe shimmer sweeps from right to left.
Changed in the M6 build (2026-10-28)
  • SkeletonState carries the resolved shape, the animation (already None under reduced motion) and the shared phase, read while painting. Core paints for the skins: Kotlin Modifier.drawSkeleton, Flutter CamoSkeletonPaint.
  • A text line is a block lineHeight − textLineGap tall 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: CamoSkeletonGroup provides LocalSkeletonPhase from rememberInfiniteTransition().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 forces None.
  • Text lines: each line's height is the style's lineHeight converted with LocalDensity, so lines match the real text at any font scale.
  • clearAndSetSemantics {} on every block.

4. Build steps​

  1. SkeletonTheme / Style, the composables, the DebugSkin renderer (static gray).
  2. commonTest: sizes; lines = 3 with 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​

CaseDecided behavior
A skeleton in a LazyColumn itemThe list's group phase is shared across items (the provider sits outside the list).
RTLThe brush moves right to left.