compose-multiplatform
暂无简介
- License 许可
- MIT
- 最近更新
- 2026-10-14
- Stars
- ★ 0
- Forks
- 0
02 资源文件 6
- 参考文档manifest.yaml2.5 KB
- 参考文档references/lists-and-scrolling.md4.7 KB
- 参考文档references/modifiers-and-layout.md5.9 KB
- 参考文档references/performance-and-stability.md11.4 KB
- 参考文档references/stability-baselines.md9.6 KB
- 参考文档references/state-management.md9.2 KB
03 SKILL.md 正文
Compose Multiplatform Skill
The mechanics of Compose Multiplatform UI: where state lives and how it is keyed, how the modifier parameter forms a component's public contract, how lazy lists stay cheap, and why a composable recomposes when it should skip.
Design-system boundaries, component contracts and theme usage are normative — see
.claude/rules/kmp/uikit.md. Screen composition, effect collection and the MVI wiring are in
.claude/rules/kmp/feature-structure.md and .claude/rules/kmp/architecture.md. This skill
implements against those rules; it does not restate them.
| If you need… | Read |
|---|---|
remember keying, derivedStateOf, hoisting boundaries, cross-phase back-writing |
references/state-management.md |
The modifier parameter contract and chain ordering |
references/modifiers-and-layout.md |
LazyColumn keys, contentType, prefetch, the O(n²) trap |
references/lists-and-scrolling.md |
| Stability classes, strong skipping, compiler reports, phase deferral | references/performance-and-stability.md |
| Gating stability in CI against a committed baseline; runtime recomposition counts on non-Android targets | references/stability-baselines.md |
| Where a component belongs and what its contract must be | .claude/rules/kmp/uikit.md |
Do not load a reference during discovery — open it when writing or diagnosing that specific thing.
Scope
In scope
- State:
rememberand its keys,rememberSaveable,derivedStateOf, hoisting decisions. - Effects: which one, keyed how, and what invalidates what.
- Modifier API contract, chain order, custom layout.
- Lazy list correctness and cost.
- Recomposition diagnosis: stability, strong skipping, phase.
- Gating stability against a committed baseline, and measuring recomposition at runtime.
- Compose Multiplatform specifics — what is Android-only and what runs in
commonMain.
Out of scope — hand off, do not answer here
- Whether a component belongs in the design system →
.claude/rules/kmp/uikit.md - Screen/feature package layout, effect collection shape →
.claude/rules/kmp/feature-structure.md - ViewModel contract,
UiState/Intent/Effect→.claude/rules/kmp/architecture.md - Obtaining a ViewModel in a composable →
koin-kmp - Navigation and routes →
.claude/rules/kmp/navigation.md - Strings and resources →
.claude/rules/kmp/localization.md - Compose UI test authoring →
kmp-testing - Compose compiler Gradle wiring →
kmp-multiplatform-specialist - iOS-embedded views →
kmp-ios-interop
Procedure
- Read the surrounding code first — the screen, its state holder, and one neighbouring component. Match the conventions already in use before introducing any.
- Name the axis before optimising. A recomposition complaint is either a stability problem (the composable runs although inputs did not change) or a phase problem (a state read happened in composition that belonged in layout or draw). Applying the wrong fix costs time and adds noise.
- Change the smallest surface. Prefer deriving over caching, hoisting over annotating.
- Verify. Run the UI tests for the affected screen and report the real output.
Composition, layout, draw
Three phases, in order. State written in a phase invalidates that phase and everything after it —
never before it. Almost every "jittery scroll", "ghost layout" or "recomposition loop" is a backward
write: layout or draw writing state that composition reads. The cure is a layout-phase API
(Modifier.layout { }, Modifier.offset { }, Modifier.graphicsLayer { }), not a MutableState
bridging the value back into composition. references/state-management.md has the shapes.
Compose Multiplatform vs Android
Several things carried over from Android tutorials do not exist or do not behave the same in
commonMain:
| Android | Compose Multiplatform |
|---|---|
rememberSaveable with Bundle / @Parcelize |
@Serializable + a kotlinx-serialization-based Saver |
collectAsStateWithLifecycle() |
collectAsState() — it does not stop collecting in the background unless a lifecycle-aware variant is available in commonMain |
LocalConfiguration |
not available; use BoxWithConstraints or the window-size-class APIs |
| Layout Inspector, Macrobenchmark, Baseline Profiles | Android-only. Desktop profiles with JVM tooling; iOS with Instruments |
painterResource(R.drawable.x) |
Compose Resources Res.drawable.x, per-module — see .claude/rules/kmp/localization.md |
The stability and phase model itself is identical across platforms; only the tooling differs.
Do NOT
- Do NOT add
@Immutable/@Stablespeculatively — under strong skipping, same-module classes with stable properties are inferred stable already, and a false promise produces stale UI. - Do NOT
rememberSaveablea runtime object (LazyListState,FocusRequester, a callback). - Do NOT build
Flowpipelines (stateIn,combine,flatMapLatest) inside a composable body. - Do NOT run a scroll or animation suspend function from
viewModelScope. - Do NOT hardcode placement (
fillMaxWidth, fixed height, outer padding) on a reusable component's root. - Do NOT nest a scrolling container inside a lazy list item.
- Do NOT optimise without a measurement that names the axis.
- Do NOT reach for
derivedStateOfwhen the block reads no ComposeState— it is pure overhead.
Error handling
- "It recomposes too much" with no measurement → say so, and ask for the recomposition counts or the compiler report first. Do not start annotating.
- A composable is reported skippable but still recomposes → the defect is at the call site, not
the callee. Name the allocation (a fresh
List,Modifierchain, or ad-hoc object per frame). - The fix would be an
@Immutableon a type with mutable non-snapshot fields → refuse and fix the type; that annotation causes silent stale UI. - The behaviour depends on Compose version → read
libs.versions.tomland say which version the answer assumes. Prefetch and cache-window APIs in particular moved recently. - "Gate stability in CI", or a red
stabilityCheck→references/stability-baselines.md. Do not hand this togradle-build-auditor(it audits build structure, not Compose semantics) or toci-cd-pipeline-builder(it writes the pipeline; the compile-before-check ordering and the plugin's Kotlin-version coupling are answered here). - The question is really about layering or where the component lives → point at
.claude/rules/kmp/uikit.mdorfeature-structure.mdand stop.
Example
"The list stutters while scrolling and the row recomposes constantly."
- Read the screen and the row component; report how
itemsis keyed and what the row's parameters are. - Name the axis. Fresh lambda or list allocated per scroll → stability. Animated or scroll-derived value read in composition → phase.
- Check the item factory for an
indexOfcall — an O(n) lookup per item is O(n²) per scroll pass and looks exactly like a recomposition problem. - Apply the one matching fix — stable
key+contentType,remember(item.id)for the per-item lambda, or moving the read intographicsLayer { }. - Re-measure and report the before/after numbers, not just "it feels smoother".
Expected outcome: one named cause, one fix, and a measurement that shows the change.
Related Skills
kmp-multiplatform-specialist— Compose compiler config, resources, source setskmp-testing— Compose test dispatching, selectors, determinismkoin-kmp— obtaining the ViewModel a screen renderskotlin-specialist—Flow,StateFlow, coroutine scope ownershipkmp-ios-interop— embedding UIKit/SwiftUI inside Composenew-feature— scaffolding the screen this UI lives in
04 同仓库更多 Skills
universal-skill
暂无简介
notion-skill
暂无简介
inline-frontmatter-skill
Hand-authored description that already lives in the body and must not be double-wrapped.
universal-skill
暂无简介
notion-skill
暂无简介
write-a-skill
暂无简介