Compose Multiplatform and Jetpack Compose patterns for KMP — state management, navigation, theming, performance, and platform-specific UI. USE WHEN building shared Compose UI across Android/iOS/Desktop/Web, managing Compose state, or optimizing recomposition.
Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Um comando direto ignora o prompt de revisão. Verifique a origem antes de executá-lo.
Instruções da origem · Visualização somente leitura
name
compose-multiplatform-patterns
description
Compose Multiplatform and Jetpack Compose patterns for KMP — state management, navigation, theming, performance, and platform-specific UI. USE WHEN building shared Compose UI across Android/iOS/Desktop/Web, managing Compose state, or optimizing recomposition.
cluster
jvm
version
1.0.0
Compose Multiplatform Patterns
Patterns for building shared UI across Android, iOS, Desktop, and Web using Compose Multiplatform and Jetpack Compose. Covers state management, navigation, theming, and performance.
When to Activate
Building Compose UI (Jetpack Compose or Compose Multiplatform)
Managing UI state with ViewModels and Compose state
Implementing navigation in KMP or Android projects
Designing reusable composables and design systems
Optimizing recomposition and rendering performance
State Management
ViewModel + Single State Object
Use a single data class for screen state. Expose it as StateFlow and collect in Compose:
@ComposablefunItemListScreen(viewModel: ItemListViewModel = koinViewModel()) {
val state by viewModel.state.collectAsStateWithLifecycle()
ItemListContent(
state = state,
onSearch = viewModel::onSearch
)
}
@ComposableprivatefunItemListContent(
state: ItemListState,
onSearch: (String) -> Unit
) {
// Stateless composable — easy to preview and test
}
Event Sink Pattern
For complex screens, use a sealed interface for events instead of multiple callback lambdas:
sealedinterfaceItemListEvent {
dataclassSearch(val query: String) : ItemListEvent
dataclassDelete(val itemId: String) : ItemListEvent
dataobject Refresh : ItemListEvent
}
// In ViewModelfunonEvent(event: ItemListEvent) {
when (event) {
is ItemListEvent.Search -> onSearch(event.query)
is ItemListEvent.Delete -> deleteItem(event.itemId)
is ItemListEvent.Refresh -> loadItems(_state.value.searchQuery)
}
}
// In Composable — single lambda instead of many
ItemListContent(
state = state,
onEvent = viewModel::onEvent
)