Loading...
Loading...
Use when designing Kotlin Multiplatform expect/actual or interface boundaries for platform services, native SDKs, source sets, Compose Multiplatform UI, permissions, files, settings, sensors, or platform interop.
npx skill4agent add chrisbanes/skills kotlin-multiplatform-expect-actualexpectactualcommonMainexpect/actual| Situation | Prefer |
|---|---|
| Simple compile-time platform specialization | |
| Implementation needs injected dependencies, lifecycle ownership, runtime choice, or test fakes | Common interface plus platform binding |
| UI is mostly shared, one leaf differs | Common composable calling an |
| Entire screen differs by platform | Separate platform screens behind a common navigation contract |
| Only constants/resources differ | Common API exposing semantic values, actual values per platform |
// GOOD: common API is semantic
expect fun currentRegion(): Region// BAD: common API leaks Android implementation
expect fun currentRegionFromAndroidLocale(context: Context): RegionLocaleexpect class// commonMain
interface ShareSheet {
suspend fun shareText(text: String)
}// androidMain
class AndroidShareSheet(
private val activity: Activity,
) : ShareSheet {
override suspend fun shareText(text: String) {
val intent = Intent(Intent.ACTION_SEND)
.setType("text/plain")
.putExtra(Intent.EXTRA_TEXT, text)
activity.startActivity(Intent.createChooser(intent, null))
}
}ContextFLAG_ACTIVITY_NEW_TASKsuspendexpect/actualinterface Clipboard {
suspend fun setText(text: String)
}ClipboardModifiercommonMainContextActivityUriBundleUIViewControllerNSBundleAndroidViewUIKitViewrememberLaunchedEffectDisposableEffect| Mistake | Fix |
|---|---|
| Replace with semantic common types |
| Move those details into the actual |
| Business branching duplicated in each actual | Move business rules to common code |
One huge | Split by capability: |
| Platform UI leaks high in the tree | Push platform-specific Composable to a leaf |
| No fakeable boundary for common tests | Use an interface instead of direct |
compose-state-holder-ui-splitcompose-side-effectsLaunchedEffectDisposableEffectcompose-modifier-and-layout-stylecompose-slot-api-pattern