Modifier.colorPulse¶
Cycles the receiver's fill colour through a sequence on a fixed period.
When to use¶
- Notification dots, "new" badges, "live" indicators, recording dots.
- Anywhere a static colour reads as "ignorable" but motion would be too much.
When not to use¶
- Text. The cycling fill will compete with the glyph colour.
- Large fills. The pulse becomes overwhelming past about 24 dp.
Usage¶
Box(
modifier = Modifier
.size(16.dp)
.colorPulse(
colors = listOf(Color(0xFFEF4444), Color(0xFFFB923C), Color(0xFFEF4444)),
shape = CircleShape,
),
)
Parameters¶
| Name | Type | Default | Notes |
|---|---|---|---|
colors | List<Color> | red / amber / red | Cycle wraps from the last back to the first. Two minimum. |
durationMs | Int | 1_600 | Time for a full pass through every colour. |
shape | Shape | CircleShape | Filled with the current interpolated colour. |
Design notes¶
- Node subtype:
DrawModifierNode. A singleAnimatable<Float>cycles0f → 1finfinitely; we map the phase onto the colour list withlerpbetween adjacent stops.FastOutSlowInEasingsoftens transitions, preventing the visible "wraparound flash" you'd get with linear easing. - Cleanup: the animation is cancelled in
onDetach(). AddingcolorPulseto a list cell that scrolls off doesn't keep frames coming. - Why not
targetBasedper-segment? A single infinite animation with phase-mapping is cheaper than a chain ofanimateTocalls and has no jank at the boundary between segments.