Agent Skills
› chrisbanes/skills
› compose-state-and-effects
compose-state-and-effects
GitHub指导Jetpack Compose中状态所有权管理、状态提升及副作用(如LaunchedEffect)的生命周期匹配,确保UI可预览和测试。
Trigger Scenarios
编写或审查Compose状态归属
处理remember、state hoisting
配置LaunchedEffect等副作用
Install
npx skills add chrisbanes/skills --skill compose-state-and-effects -g -y
SKILL.md
Frontmatter
{
"name": "compose-state-and-effects",
"description": "Use when writing or reviewing Jetpack Compose state ownership, remember state, state hoisting, screen state holders, LaunchedEffect, DisposableEffect, SideEffect, Flow collection, navigation, snackbar, analytics, or focus requests."
}
Compose state and effects
Core principle
Give every piece of UI state one lowest responsible owner, then run imperative work through the effect whose lifecycle follows that owner. Composition renders; state and effects make rendering change safely.
Procedure
- Establish the requested scope and visible behavioral requirements. Treat an ownership change as a finding only when code or task evidence shows a lifecycle, testability, business, or coordination need.
- Inventory mutable UI state, app state, event streams, app dependencies, and imperative work in the affected screen or component.
- Place each state value at its lowest necessary owner: local UI state, hoisted state, a plain UI state holder, or a screen state holder.
- For a screen boundary, keep durable data and intents in the wiring owner, Compose runtime objects in composition or a plain UI state holder, and rendering in a previewable content composable that takes immutable state and callbacks. Read State hoisting for the implementation shape; naming only state and intents is not that boundary.
- Choose an effect API whose lifecycle matches the work, and key it by the semantic input that should restart or dispose it.
- Load the focused reference for every material concern below. Do not use a reference merely because its topic is adjacent.
- Route frame-rate reads, cross-phase back-writing, and
@ReadOnlyComposablecontracts to Compose performance. - Before responding to a screen-ownership review, verify all three screen seams in step 4 when visible code needs them.
- Finish when every state value has one owner, every effect has a justified lifecycle and key, and the UI can be previewed and tested without app dependencies. For review-only work, report no change when no evidence-backed issue remains; do not invent product requirements.
Topic router
| Signal | Read |
|---|---|
Bare local var, remember { mutableStateOf(...) }, state lists/maps, or reset state |
Local state |
| State shared by siblings, UI state holders, ViewModel/component wiring, or previewable screen boundaries | State hoisting |
LaunchedEffect, DisposableEffect, SideEffect, snapshotFlow, rememberCoroutineScope, rememberUpdatedState, produceState, imperative requestFocus, callbacks, event Flow collection, snackbar, navigation, or analytics |
Side effects |
| Focus ownership and keyboard/TV/D-pad behavior | Compose focus navigation |
| Tests or previews for the resulting UI contract | Compose UI testing patterns |
Version History
-
2026.8.24
Current 2026-08-27 17:15
减少技能说明的冗余度,优化指令简洁性。
-
2026.8.16
2026-08-19 19:31
新增步骤1以明确需求范围;细化步骤4关于屏幕边界与可预览Composable的规范;更新步骤8增加对三个必要接口的验证要求。
- 2026.8.5 2026-08-16 02:44


