compose-state-deferred-reads
Installation
SKILL.md
Compose state deferred reads
Core principle
State reads invalidate the phase that reads them. If a State<T> is read in a composable body, changes invalidate composition. If it is read in layout or draw, changes can invalidate only layout or draw. Frame-rate state such as scroll offsets, animations, and drag positions usually belongs in layout/draw, not composition.
The fix is structural: keep the State<T> or a provider lambda, and read the value inside a layout/draw callback.
When to use this skill
val x by animate*AsState(...)is passed toModifier.offset(x = ...),Modifier.size(...),Modifier.graphicsLayer(...), or another value-form modifier.LazyListState.firstVisibleItemScrollOffset,ScrollState.value,Animatable.value, or gesture state is read in a composable body.- A composable takes
scrollOffset: Int,progress: Float,dragOffset: Offset, or similar frame-rate values. - Recomposition counters climb during scroll, animation, or gestures even when data is stable.
1. Prefer block-form modifiers
Several modifiers have value forms and block forms. The value form receives values already read in composition; the block form can read during layout or draw.