Compose Multiplatform Patterns

Compose Multiplatform and Jetpack Compose patterns for KMP projects — state management, navigation, theming, performance, and…

You say
Install this skill Read the source first Free Written by affaan-m · unverified publisher
Context cost
2k tokensestimated from the bundle, loaded when it triggers
Bundle
1 file · 8.2 kBtext throughout, nothing executable
Licence
MITfree to use
Last change
no release on file
Servers it uses
Noneruns standalone

What it does

Compose Multiplatform and Jetpack Compose patterns for KMP projects — state management, navigation, theming, performance, and platform-specific UI. Use when building Compose or Jetpack Compose UI, state, navigation, or theming in a KMP project.

Installed, it changes the agent in these ways.

What this skill changes about the agent is not written down here yet. The listing was collected from its source, and the description is in its own SKILL.md.

Expertise

Domain judgement the base model does not have.

mobileperformance

The skill itself

This is the whole product. A skill is instructions the model reads, so there is nothing behind the listing you cannot see first — the front matter loads with every session, and the body below it loads when the skill triggers.

SKILL.md8.2 kB · 301 lines
--- name: compose-multiplatform-patterns description: Compose Multiplatform and Jetpack Compose patterns for KMP projects — state management, navigation, theming, performance, and platform-specific UI. Use when building Compose or Jetpack Compose UI, state, navigation, or theming in a KMP project. metadata: origin: ECC ---
8# Compose Multiplatform Patterns
9
10Patterns for building shared UI across Android, iOS, Desktop, and Web using Compose Multiplatform and Jetpack Compose. Covers state management, navigation, theming, and performance.
11
12## When to Activate
13
14- Building Compose UI (Jetpack Compose or Compose Multiplatform)
15- Managing UI state with ViewModels and Compose state
16- Implementing navigation in KMP or Android projects
17- Designing reusable composables and design systems
18- Optimizing recomposition and rendering performance
19
20## State Management
21
22### ViewModel + Single State Object
23
24Use a single data class for screen state. Expose it as StateFlow and collect in Compose:
25
26```kotlin
27data class ItemListState(
28 val items: List<Item> = emptyList(),
29 val isLoading: Boolean = false,
30 val error: String? = null,
31 val searchQuery: String = ""
32)
33
34class ItemListViewModel(
35 private val getItems: GetItemsUseCase
36) : ViewModel() {
37 private val _state = MutableStateFlow(ItemListState())
38 val state: StateFlow<ItemListState> = _state.asStateFlow()
39
40 fun onSearch(query: String) {
41 _state.update { it.copy(searchQuery = query) }
42 loadItems(query)
43 }
44
45 private fun loadItems(query: String) {
46 viewModelScope.launch {
47 _state.update { it.copy(isLoading = true) }
48 getItems(query).fold(
49 onSuccess = { items -> _state.update { it.copy(items = items, isLoading = false) } },
50 onFailure = { e -> _state.update { it.copy(error = e.message, isLoading = false) } }
51 )
52 }
53 }
54}
55```
56
57### Collecting State in Compose
58
59```kotlin
60@Composable
61fun ItemListScreen(viewModel: ItemListViewModel = koinViewModel()) {
62 val state by viewModel.state.collectAsStateWithLifecycle()
63
64 ItemListContent(
65 state = state,
66 onSearch = viewModel::onSearch
67 )
68}
69
70@Composable
71private fun ItemListContent(
72 state: ItemListState,
73 onSearch: (String) -> Unit
74) {
75 // Stateless composable — easy to preview and test
76}
77```
78
79### Event Sink Pattern
80
81For complex screens, use a sealed interface for events instead of multiple callback lambdas:
82
83```kotlin
84sealed interface ItemListEvent {
85 data class Search(val query: String) : ItemListEvent
86 data class Delete(val itemId: String) : ItemListEvent
87 data object Refresh : ItemListEvent
88}
89
90// In ViewModel
91fun onEvent(event: ItemListEvent) {
92 when (event) {
93 is ItemListEvent.Search -> onSearch(event.query)
94 is ItemListEvent.Delete -> deleteItem(event.itemId)
95 is ItemListEvent.Refresh -> loadItems(_state.value.searchQuery)
96 }
97}
98
99// In Composable — single lambda instead of many
100ItemListContent(
101 state = state,
102 onEvent = viewModel::onEvent
103)
104```
105
106## Navigation
107
108### Type-Safe Navigation (Compose Navigation 2.8+)
109
110Define routes as @Serializable objects:
111
112```kotlin
113@Serializable data object HomeRoute
114@Serializable data class DetailRoute(val id: String)
115@Serializable data object SettingsRoute
116
117@Composable
118fun AppNavHost(navController: NavHostController = rememberNavController()) {
119 NavHost(navController, startDestination = HomeRoute) {
120 composable<HomeRoute> {
121 HomeScreen(onNavigateToDetail = { id -> navController.navigate(DetailRoute(id)) })
122 }
123 composable<DetailRoute> { backStackEntry ->
124 val route = backStackEntry.toRoute<DetailRoute>()
125 DetailScreen(id = route.id)
126 }
127 composable<SettingsRoute> { SettingsScreen() }
128 }
129}
130```
131
132### Dialog and Bottom Sheet Navigation
133
134Use dialog() and overlay patterns instead of imperative show/hide:
135
136```kotlin
137NavHost(navController, startDestination = HomeRoute) {
138 composable<HomeRoute> { /* ... */ }
139 dialog<ConfirmDeleteRoute> { backStackEntry ->
140 val route = backStackEntry.toRoute<ConfirmDeleteRoute>()
141 ConfirmDeleteDialog(
142 itemId = route.itemId,
143 onConfirm = { navController.popBackStack() },
144 onDismiss = { navController.popBackStack() }
145 )
146 }
147}
148```
149
150## Composable Design
151
152### Slot-Based APIs
153
154Design composables with slot parameters for flexibility:
155
156```kotlin
157@Composable
158fun AppCard(
159 modifier: Modifier = Modifier,
160 header: @Composable () -> Unit = {},
161 content: @Composable ColumnScope.() -> Unit,
162 actions: @Composable RowScope.() -> Unit = {}
163) {
164 Card(modifier = modifier) {
165 Column {
166 header()
167 Column(content = content)
168 Row(horizontalArrangement = Arrangement.End, content = actions)
169 }
170 }
171}
172```
173
174### Modifier Ordering
175
176Modifier order matters — apply in this sequence:
177
178```kotlin
179Text(
180 text = "Hello",
181 modifier = Modifier
182 .padding(16.dp) // 1. Layout (padding, size)
183 .clip(RoundedCornerShape(8.dp)) // 2. Shape
184 .background(Color.White) // 3. Drawing (background, border)
185 .clickable { } // 4. Interaction
186)
187```
188
189## KMP Platform-Specific UI
190
191### expect/actual for Platform Composables
192
193```kotlin
194// commonMain
195@Composable
196expect fun PlatformStatusBar(darkIcons: Boolean)
197
198// androidMain
199@Composable
200actual fun PlatformStatusBar(darkIcons: Boolean) {
201 val systemUiController = rememberSystemUiController()
202 SideEffect { systemUiController.setStatusBarColor(Color.Transparent, darkIcons) }
203}
204
205// iosMain
206@Composable
207actual fun PlatformStatusBar(darkIcons: Boolean) {
208 // iOS handles this via UIKit interop or Info.plist
209}
210```
211
212## Performance
213
214### Stable Types for Skippable Recomposition
215
216Mark classes as @Stable or @Immutable when all properties are stable:
217
218```kotlin
219@Immutable
220data class ItemUiModel(
221 val id: String,
222 val title: String,
223 val description: String,
224 val progress: Float
225)
226```
227
228### Use key() and Lazy Lists Correctly
229
230```kotlin
231LazyColumn {
232 items(
233 items = items,
234 key = { it.id } // Stable keys enable item reuse and animations
235 ) { item ->
236 ItemRow(item = item)
237 }
238}
239```
240
241### Defer Reads with derivedStateOf
242
243```kotlin
244val listState = rememberLazyListState()
245val showScrollToTop by remember {
246 derivedStateOf { listState.firstVisibleItemIndex > 5 }
247}
248```
249
250### Avoid Allocations in Recomposition
251
252```kotlin
253// BAD — new lambda and list every recomposition
254items.filter { it.isActive }.forEach { ActiveItem(it, onClick = { handle(it) }) }
255
256// GOOD — key each item so callbacks stay attached to the right row
257val activeItems = remember(items) { items.filter { it.isActive } }
258activeItems.forEach { item ->
259 key(item.id) {
260 ActiveItem(item, onClick = { handle(item) })
261 }
262}
263```
264
265## Theming
266
267### Material 3 Dynamic Theming
268
269```kotlin
270@Composable
271fun AppTheme(
272 darkTheme: Boolean = isSystemInDarkTheme(),
273 dynamicColor: Boolean = true,
274 content: @Composable () -> Unit
275) {
276 val colorScheme = when {
277 dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
278 if (darkTheme) dynamicDarkColorScheme(LocalContext.current)
279 else dynamicLightColorScheme(LocalContext.current)
280 }
281 darkTheme -> darkColorScheme()
282 else -> lightColorScheme()
283 }
284
285 MaterialTheme(colorScheme = colorScheme, content = content)
286}
287```
288
289## Anti-Patterns to Avoid
290
291- Using mutableStateOf in ViewModels when MutableStateFlow with collectAsStateWithLifecycle is safer for lifecycle
292- Passing NavController deep into composables — pass lambda callbacks instead
293- Heavy computation inside @Composable functions — move to ViewModel or remember {}
294- Using LaunchedEffect(Unit) as a substitute for ViewModel init — it re-runs on configuration change in some setups
295- Creating new object instances in composable parameters — causes unnecessary recomposition
296
297## References
298
299See skill: android-clean-architecture for module structure and layering.
300See skill: kotlin-coroutines-flows for coroutine and Flow patterns.
301
In the file
SKILL.md971 words
Files1
LicenceMIT
Why you can read it

Nothing in a skill executes. The client loads the text and the model follows it, so a skill can be audited the way a runbook is — by reading it.

What it costs in context

Skills are not billed by the call. They are paid for in context: every token the instructions occupy is a token your code, your diff and your conversation cannot use. Here is what this one takes and when it takes it.

≈80
always loaded
The name and description, so the model knows the skill exists and when to reach for it.
1,970
on trigger
The instruction body, read only when the skill fires.
1.0%
of a 200k window
Ten skills this size would take about 10% of the window before you open a file.
050k100k150k200k context window

2k tokens, estimated from the bundle at four bytes to the token, held for the rest of the session once it triggers. Middling. Fine to keep on in a project where you use it weekly, worth unloading in one where you never do.

Servers bill, skills cost

A server charges by the month. A skill charges once per session, in context, and then keeps charging it for as long as the session lives.

Before and after

The same question, put to the same model twice: once as it comes, and once with these instructions loaded.

No worked example has been published for this skill yet.

Adoption
Installsnone yet
Ratingno reviews yet

The procedure it runs

The procedure has not been published here. It is in the skill’s own SKILL.md, which its author has not sent to the marketplace yet.

Prose, not code

These steps are written for a model to follow, not executed by a runtime. It can still be told to skip one, and it will say so when it does.

Servers it uses

None. This skill calls no MCP servers at all.

Everything it needs is in the instructions, so it works in a project with nothing connected — the model reads the file and changes how it works with what it can already reach.

It writes no files and reaches no network. All it changes is how the model reasons and writes.

What it asks for
Writes filesno
Network accessno

Read from the allowed-tools line of this skill’s own SKILL.md. A skill grants no permissions of its own — it can only ask for tools your client already has.

What it will not do

Every skill is narrow, and the useful ones say where they stop. These are the jobs this one is the wrong tool for.

What this skill is not for has not been published here. Nothing is implied by that: it is a section the author has not filled in.

What is in the bundle

1 file, 8.2 kB on disk. A bundle is text throughout: the instructions the model reads, plus the templates it fills in.

  • SKILL.md8.2 kB
What is not in it

No dependencies and nothing executable: a skill is text the agent reads, so the bundle is 1 file you can review in full before installing. The MIT licence covers the templates and examples as well as the instructions.

Install

Installing copies the bundle into your project. Nothing runs at install time — the files sit on disk until the model reads them.

# Compose Multiplatform Patterns · 2k tokens when loaded npx mcprush@latest skill add affaan-m/compose-multiplatform-patterns

Writes to .claude/skills/compose-multiplatform-patterns/ in the current project. Add --global to put it in your home directory instead, for every project.

Which clients pick it up on their own

A skill is a folder of text. A client with a skills folder reads it without being told; everywhere else the same text works, it is just handed to the model rather than found.

Claude Code.claude/skills/
Claude Desktop
ChatGPT
Cursor.cursor/skills/
VS Code.github/skills/
Codex CLI.agents/skills/
Gemini CLI.gemini/skills/
Grok.grok/skills/
Zed.agents/skills/
Windsurf.windsurf/skills/
Agent SDK.claude/skills/
HTTP / API
This release
Versionnot versioned
Publishedno release date on file
PriceFree
Referenceaffaan-m/compose-multiplatform-patterns

Versions

Its author publishes no version number, so there is nothing here to pin to: what you install is the folder as it stands today. Instructions change more often than APIs do — a skill can be rewritten entirely without anything it depends on moving.

v
  • No earlier releases have been published to the marketplace.
Pinning

Nothing to pin to: this skill carries no version number of its own. What you install is what the folder holds on the day you install it.

Reviews

no reviews yet · no installs yet

Nobody has reviewed this skill yet. The rating is the mean of the reviews written here, so there is none until somebody writes the first.

Who can post

Only accounts that have had the skill installed for fourteen days, so a review is written after living with it rather than after reading it. Publishers may reply once.

Publisher
Servers0