What does this skill do?

The Patrones Compose Multiplatform Skill provides a set of proven patterns for building shared interfaces across Android, iOS, desktop, and the web using Compose Multiplatform and Jetpack Compose. It covers state management with ViewModels and StateFlow, type-safe navigation, stateless composables, platform-specific integration with expect/actual, and recomposition optimization for optimal performance.

Centralized UI Status
Define a single immutable state object per screen and expose it from the ViewModel as a StateFlow.
Browsing with Secure Types
Use @Serializable paths instead of strings for type-safe navigation without runtime errors.
Platform-Specific UI
Isolate platform-specific code using `expect/actual` for status bars, sensors, or native APIs on Android and iOS.
Recomposition Optimization
Mark models as @Immutable, use stable keys in lists, and use derivedStateOf to reduce recompositions.

Usage examples

🏗️ ViewModel with state
Create a ViewModel for a product list screen with a single state, sealed events, and asynchronous loading using StateFlow.
🧭 Typed Navigation
Configure a NavHost with navigation between HomeRoute and DetailRoute using @Serializable safe types.
📱 Expect/Actual Integration
Create a PlatformStatusBar function with "expected/actual" values for Android and iOS that adjusts the status bar color.
⚡ List Optimization
Optimize a LazyColumn using @Immutable models, stable keys, and derivedStateOf to display a "scroll-to-top" button.

Features

One status per screen An immutable data class pattern exposed as a StateFlow and collected using `collectAsStateWithLifecycle`.
Stateless composables Design of stateless composables using slot-based APIs for maximum reusability and testability.
Browsing with Secure Types @Serializable routes instead of strings, preventing runtime errors when navigating.
Expect/Actual Cross-Platform Integration Clean, platform-specific code isolation for Android, iOS, desktop, and the web.
Optimized Performance @Immutable and @Stable annotations, stable keys in lists, and derivedStateOf to minimize recompositions.

Frequently asked questions

Yes. This skill assumes that you already have a Kotlin Multiplatform project with Compose Multiplatform enabled. The patterns are applied to your existing structure.
It works with both. The patterns cover shared code in `commonMain` and platform-specific integration using `expect/actual` for Android and iOS.
We recommend using recent versions of Compose Multiplatform that support type-safe navigation (@Serializable) and collectAsStateWithLifecycle.
Yes. The patterns are modular: you can apply just the state, navigation, or performance optimization, depending on your needs.
Compose Multiplatform Templates — Shared Android and iOS UI with Claude AI

¿Prefieres escuchar el contenido? Genera la narración de audio con un clic.