deferring-state-reads

Migrates hot Jetpack Compose state reads from Composition to Layout or Draw phases using lambda modifiers.

1|Updated Jul 6, 2026
One-click install
npx skills add https://github.com/citytexi/team-yg-pesonal-agent --skill deferring-state-reads-citytexi
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: deferring-state-reads
Source: https://github.com/citytexi/team-yg-pesonal-agent/tree/main/.claude/skills/deferring-state-reads
Command: npx skills add https://github.com/citytexi/team-yg-pesonal-agent --skill deferring-state-reads-citytexi

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Jetpack Compose UIs that read frequently-changing state (scroll position, animation values, drag offsets) inside composable bodies recompose entire subtrees every frame, causing scroll jank, animation jank, and dropped frames. This Skill diagnoses wrong-phase state reads and migrates them to lambda-based modifiers so invalidation is confined to Layout or Draw. ## Core Features & Use Cases - Value-to-lambda modifier migration: Converts Modifier.alpha(state.value), Modifier.offset(x.dp), Modifier.background(color) into Modifier.graphicsLayer { }, Modifier.offset { IntOffset(...) }, and Modifier.drawBehind { } forms. - Lambda provider pattern: Rewrites hot values passed across composables from Float parameters to () -> Float providers so parents never recompose per frame. - Phase cheat sheet and verification: Provides a modifier-phase reference table plus Layout Inspector and @TraceRecomposition verification steps on release builds. - Use Case: A scroll-driven sticky header recomposes the whole screen on every pixel of scroll; the Skill rewrites it to Modifier.offset { IntOffset(0, scrollState.value) } so only Layout re-runs. ## Quick Start Ask the assistant to fix the per-frame recomposition in your composable by moving the animated alpha and scroll offset reads into lambda-based modifiers like graphicsLayer and offset.

Frequently Asked Questions about deferring-state-reads

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I stop Jetpack Compose from recomposing on every animation frame?▼

Move the state read out of the composable body into a lambda modifier such as Modifier.graphicsLayer { alpha = value } or Modifier.offset { IntOffset(x, 0) }. The lambda reads state during Layout or Draw, so Composition is never invalidated per frame.

What is the difference between Modifier.offset(x.dp) and Modifier.offset { }?▼

Modifier.offset(x: Dp) reads its value in the Composition phase, invalidating the whole subtree when the value changes. Modifier.offset { IntOffset } reads in the Layout phase, so only re-placement occurs and Composition is skipped.

Does Modifier.padding have a lambda form for animated insets?▼

No, Modifier.padding ships only value-based overloads, so it always reads in Composition. For animated insets driven by hot state, use a custom Modifier.layout { measurable, constraints -> ... } block instead.

When should I use drawBehind versus drawWithCache in Compose?▼

Use Modifier.drawBehind for simple per-frame drawing like a solid animated color. Use Modifier.drawWithCache when the work involves rebuildable resources such as paths, brushes, or gradients, since it caches the build step and only re-runs onDraw on state change.

When should I not use lambda-based modifiers for state reads?▼

Avoid them when state changes only once per user interaction, or when the state decides which composable to emit, since lambda modifiers cannot change the emitted tree. Also diagnose stability issues first if the parent is non-skippable due to unstable parameters.

Why does my Compose animation still jank after using lambda modifiers?▼

A wrong-phase read likely survived elsewhere in the file; re-grep for .value and by state in composable bodies. Also confirm measurements on a release build with R8 on a real device, since debug builds run interpreted and misrepresent cost.