shennawardana23/skillme/compose-multiplatform-patterns
Claude Code and agent skill by shennawardana23/skillme
- community
Checking that the SKILL.md file is still in the repository.
Patterns for building shared UI across Android, iOS, Desktop, and Web with Compose Multiplatform and Jetpack Compose — state hoisting with ViewModel/StateFlow, type-safe navigation, slot-based composables, recomposition performance, and expect/actual platform code. Use when writing or reviewing Compose UI, wiring a ViewModel to a screen, debugging unnecessary recomposition, or adding platform-specific behavior in a KMP project.
Install
npx vskill@latest install shennawardana23/skillme/compose-multiplatform-patternsSKILL.md
The same SKILL.md was published earlier as shennawardana23/skillme/compose-multiplatform-patterns.
Compose Multiplatform Patterns
Shared UI across Android, iOS, Desktop, and Web via Compose Multiplatform, plus Jetpack Compose specifics on Android. Core mental model: state flows down as an immutable snapshot, events flow up as callbacks — the same unidirectional-data-flow discipline as SwiftUI or React, expressed with Kotlin's StateFlow and Compose's recomposition system instead of a virtual DOM diff.
When to use
Building Compose UI (Jetpack Compose or Compose Multiplatform); wiring ViewModels to screen state; implementing navigation in a KMP or Android project; designing reusable composables; diagnosing excess recomposition or janky lists.
State management
Single state data class per screen, exposed as StateFlow, collected with lifecycle awareness:
collectAsStateWithLifecycle (not plain collectAsState) stops collecting when the composable leaves the started lifecycle state, avoiding wasted work and leaked collection in backgrounded screens.
Event sink for complex screens: replace a growing pile of callback lambdas with one sealed-interface event and a single onEvent lambda — easier to log, test, and extend without changing every call site:
Navigation
Compose Navigation 2.8+ supports type-safe routes as @Serializable objects/classes instead of string paths — the compiler catches a missing or mistyped argument instead of a runtime crash on navigation:
Use dialog<Route>() for dialogs/bottom sheets so open/close state lives in the back stack, not in an imperative showDialog boolean scattered across composables.
Composable design
Slot-based APIs over one big prop bag — callers compose exactly the content they need instead of fighting a fixed configuration surface:
Modifier order changes rendered output — modifiers apply as a chain, so padding().background() and background().padding() produce visibly different results:
Platform-specific code (expect/actual)
Keep expect declarations at the smallest surface that actually differs per platform — a whole differing screen belongs behind a shared interface injected per-platform, not an expect fun per widget.
Performance
Stability drives skippability. Compose skips recomposing a function whose inputs are unchanged only if it can prove those inputs are stable. Mark data classes @Immutable (all properties never change after construction) or @Stable (properties may change but notify Compose via equals/snapshot state) so the compiler can actually make that guarantee instead of conservatively recomposing every time:
Stable keys in lazy lists let Compose track which physical row maps to which data item across reordering, insertion, and deletion, so item identity — and any remembered per-item state — survives instead of being reset:
Defer expensive reads with `derivedStateOf` so a value that's expensive to compute — or that only needs to change occasionally — doesn't trigger recomposition on every upstream state tick:
Don't allocate a fresh lambda per item inside a loop without a stable key — Compose can't tell the new lambda apart from the old one across recompositions, so any state tied to that row's identity (focus, animation) resets. Fixing this is two separate concerns: hoist the filter/derived list out with remember(items) so it isn't recomputed every recomposition, and wrap each row in key(item.id) { ... } so Compose tracks row identity independent of the lambda captured inside it.
Theming
Gotchas
mutableStateOfinside a ViewModel survives configuration changes but
isn't lifecycle-aware the way StateFlow + collectAsStateWithLifecycle is — prefer StateFlow for anything a screen collects.
- Passing
NavControllerdeep into child composables couples them to
navigation; pass lambda callbacks instead so a composable can be reused or previewed without a real NavHost.
- Heavy computation inside a
@Composablefunction body reruns on every
recomposition unless wrapped in remember{} — move it to the ViewModel or memoize it explicitly.
LaunchedEffect(Unit)is not a ViewModel-init substitute: on some
navigation/configuration-change paths it re-runs, silently re-triggering "one-time" setup.
- Creating a new object instance (a new lambda, a new data class instance)
as a composable parameter on every call defeats stability checks even if the underlying data hasn't changed — construct it once and hoist it.
Real-world grounding
The @Immutable/@Stable contract and its effect on skippable recomposition is Jetpack Compose's own documented performance model — this is not a project convention, it's how the compiler and runtime decide whether to skip a composable. Compose Multiplatform (JetBrains' extension of Jetpack Compose to iOS, Desktop, and Web) inherits this same recomposition model, so a stability bug reproduces identically across platforms even though the surrounding platform code differs.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/compose-multiplatform-patterns/SKILL.md
Popularity
- Repository stars
- 2
- 7-day trend score
- 5
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/shennawardana23/skillme/compose-multiplatform-patterns)