Apply Compose Multiplatform patterns for UI architecture, navigation, theming, and performance.
Copy the install command and let the AI configure it · recommended for beginners
Please install the "compose-multiplatform-patterns" skill from askskill: 1. Download https://raw.githubusercontent.com/affaan-m/ECC/main/skills/compose-multiplatform-patterns/SKILL.md 2. Save it as ~/.claude/skills/compose-multiplatform-patterns/SKILL.md 3. Reload skills and tell me it's ready
Design a state management pattern for a Compose Multiplatform list screen using a ViewModel and a single state object. Include loading, error, search, and item list states, plus an example of collecting state in Compose.
A KMP/Compose-friendly example with a state data class, ViewModel StateFlow, and Compose state collection.
Refactor a Compose screen with search, delete, and refresh callbacks into a sealed interface event model, and show how the ViewModel can handle everything through onEvent.
A unified event definition and ViewModel dispatch flow that reduces scattered callback parameters.
Create a type-safe navigation example for Compose Navigation 2.8+ with home, detail, and settings routes, suitable for KMP or Android projects.
A sample navigation structure based on serializable route objects and organized navigation flow.
Developers building shared Compose UI across Android, iOS, Desktop, and Web can use these patterns to standardize state management, component structure, and screen organization.
When screen logic becomes complex and callbacks multiply, this skill helps teams adopt a single state object and unified event entry pattern for better maintainability and testability.
When designing navigation, theming, and reusable composables in KMP or Android projects, these patterns provide a more consistent implementation approach.
The documentation outlines patterns for building shared UI across Android, iOS, Desktop, and Web with Compose Multiplatform and Jetpack Compose. It focuses on state management, navigation, theming, and performance. The excerpt shows a single state object with ViewModel and StateFlow, collecting state in Compose, using a sealed event interface for complex screens, and introducing type-safe navigation with Compose Navigation 2.8+.
Patterns for building shared UI across Android, iOS, Desktop, and Web using Compose Multiplatform and Jetpack Compose. Covers state management, navigation, theming, and performance.
Use a single data class for screen state. Expose it as StateFlow and collect in Compose:
data class ItemListState(
val items: List<Item> = emptyList(),
val isLoading: Boolean = false,
val error: String? = null,
val searchQuery: String = ""
)
class ItemListViewModel(
private val getItems: GetItemsUseCase
) : ViewModel() {
private val _state = MutableStateFlow(ItemListState())
val state: StateFlow<ItemListState> = _state.asStateFlow()
fun onSearch(query: String) {
_state.update { it.copy(searchQuery = query) }
loadItems(query)
}
private fun loadItems(query: String) {
viewModelScope.launch {
_state.update { it.copy(isLoading = true) }
getItems(query).fold(
onSuccess = { items -> _state.update { it.copy(items = items, isLoading = false) } },
onFailure = { e -> _state.update { it.copy(error = e.message, isLoading = false) } }
)
}
}
}
@Composable
fun ItemListScreen(viewModel: ItemListViewModel = koinViewModel()) {
val state by viewModel.state.collectAsStateWithLifecycle()
ItemListContent(
state = state,
onSearch = viewModel::onSearch
)
}
@Composable
private fun ItemListContent(
state: ItemListState,
onSearch: (String) -> Unit
) {
// Stateless composable — easy to preview and test
}
For complex screens, use a sealed interface for events instead of multiple callback lambdas:
sealed interface ItemListEvent {
data class Search(val query: String) : ItemListEvent
data class Delete(val itemId: String) : ItemListEvent
data object Refresh : ItemListEvent
}
// In ViewModel
fun onEvent(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
)
Define routes as @Serializable objects:
@Serializable data object HomeRoute
@Serializable data class DetailRoute(val id: String)
@Serializable data object SettingsRoute
@Composable
fun AppNavHost(navController: NavHostController = rememberNavController()) {
NavHost(navController, startDestination = HomeRoute) {
composable<HomeRoute> {
HomeScreen(onNavigateToDetail = { id -> navController.navigate(DetailRoute(id)) })
}
composable<DetailRoute> { backStackEntry ->
val route = backStackEntry.toRoute<DetailRoute>()
DetailScreen(id = route.id)
}
composable<SettingsRoute> { SettingsScreen() }
}
}
Use dialog() and overlay patterns instead of imperative show/hide:
NavHost(navController, startDestination = HomeRoute) {
composable<HomeRoute> { /* ... */ }
dialog<ConfirmDeleteRoute> { backStackEntry ->
val route = backStackEntry.toRoute<ConfirmDeleteRoute>()
ConfirmDeleteDialog(
itemId = route.itemId,
onConfirm = { navController.popBackStack() },
…
It provides common implementation patterns for Compose Multiplatform and Jetpack Compose, focusing on shared UI, state management, navigation, theming, and performance optimization.
The documentation explicitly targets KMP projects and scenarios where UI is built with Jetpack Compose or Compose Multiplatform.
The provided content includes ViewModel plus a single state object, collecting StateFlow in Compose, an event sink pattern, and type-safe navigation with Compose Navigation 2.8+. For more details, see the source repository.
Provides systematic verification for Claude Code sessions to improve correctness and quality.
Apply Laravel security best practices for auth, vulnerabilities, APIs, and deployment.
Safely automate SSH collection, parsing, and controlled network changes with Netmiko.
Learn secure Perl practices to prevent common code and web vulnerabilities.
Coordinate multi-agent teamwork with ownership, Kanban flow, merge gates, and handoffs.
Create consistent fundraising documents, financial projections, and investor-facing materials.
Learn practical Kotlin Coroutines and Flow patterns for Android and KMP.
Apply idiomatic Kotlin patterns to build robust, efficient, maintainable applications.
Learn practical Kotlin Ktor server patterns for building and testing backend apps.
Get practical Docker and Compose patterns for secure local multi-service development.
Build React microfrontends with shared dependencies, dynamic forms, and state management.
Learn frontend patterns for React, Next.js, state, performance, and UI best practices.