@istmx/skills 1.1.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/CODE_OF_CONDUCT.md +47 -0
  2. package/LICENSE +30 -0
  3. package/README.md +48 -22
  4. package/bin/cli.js +130 -119
  5. package/istm-animate/SKILL.md +28 -58
  6. package/istm-animate/core/motion-principles/SKILL.md +284 -0
  7. package/istm-animate/core/motion-principles/references/designers.md +127 -0
  8. package/istm-animate/core/motion-principles/references/easing-guide.md +231 -0
  9. package/istm-animate/core/motion-principles/references/enter-exit-recipes.md +466 -0
  10. package/istm-animate/frameworks/canvas-generative/SKILL.md +325 -0
  11. package/istm-animate/frameworks/canvas-generative/references/algorithms.md +925 -0
  12. package/istm-animate/frameworks/css-native/SKILL.md +319 -0
  13. package/istm-animate/frameworks/css-native/references/modern-css.md +465 -0
  14. package/istm-animate/frameworks/framer-motion/SKILL.md +187 -0
  15. package/istm-animate/frameworks/framer-motion/references/api.md +312 -0
  16. package/istm-animate/frameworks/gsap/SKILL.md +188 -0
  17. package/istm-animate/frameworks/gsap/references/core.md +218 -0
  18. package/istm-animate/frameworks/gsap/references/plugins.md +371 -0
  19. package/istm-animate/frameworks/gsap/references/scrolltrigger.md +325 -0
  20. package/istm-animate/frameworks/gsap/references/timeline.md +218 -0
  21. package/istm-animate/frameworks/threejs-r3f/SKILL.md +243 -0
  22. package/istm-animate/frameworks/threejs-r3f/references/scene-setup.md +392 -0
  23. package/istm-animate/frameworks/threejs-r3f/references/shaders.md +446 -0
  24. package/istm-animate/mobile/android/compose-graphics/SKILL.md +503 -0
  25. package/istm-animate/mobile/android/compose-graphics/references/agsl-recipes.md +356 -0
  26. package/istm-animate/mobile/android/compose-graphics/references/canvas-generative.md +282 -0
  27. package/istm-animate/mobile/android/compose-graphics/references/m3-expressive-deep.md +303 -0
  28. package/istm-animate/mobile/android/compose-motion/SKILL.md +359 -0
  29. package/istm-animate/mobile/android/compose-motion/references/gestures-compose.md +273 -0
  30. package/istm-animate/mobile/android/compose-motion/references/recomposition-and-anim.md +196 -0
  31. package/istm-animate/mobile/android/compose-motion/references/shared-transitions.md +281 -0
  32. package/istm-animate/mobile/android/compose-multiplatform/SKILL.md +311 -0
  33. package/istm-animate/mobile/android/compose-multiplatform/references/cmp-interop.md +288 -0
  34. package/istm-animate/mobile/android/compose-multiplatform/references/cmp-platform-quirks.md +156 -0
  35. package/istm-animate/mobile/apple/swiftui-graphics/SKILL.md +408 -0
  36. package/istm-animate/mobile/apple/swiftui-graphics/references/canvas-swiftui.md +239 -0
  37. package/istm-animate/mobile/apple/swiftui-graphics/references/liquid-glass-deep.md +252 -0
  38. package/istm-animate/mobile/apple/swiftui-graphics/references/metal-recipes.md +382 -0
  39. package/istm-animate/mobile/apple/swiftui-motion/SKILL.md +379 -0
  40. package/istm-animate/mobile/apple/swiftui-motion/references/gestures-swiftui.md +336 -0
  41. package/istm-animate/mobile/apple/swiftui-motion/references/phase-keyframe-deep.md +231 -0
  42. package/istm-animate/mobile/apple/swiftui-motion/references/springs-cheatsheet.md +129 -0
  43. package/istm-animate/references/animate.md +199 -0
  44. package/istm-animate/references/audit.md +115 -0
  45. package/istm-animate/references/design-engineering.md +674 -0
  46. package/istm-animate/references/improve.md +101 -0
  47. package/istm-animate/references/opportunities.md +132 -0
  48. package/istm-animate/references/plan-template.md +73 -0
  49. package/istm-animate/references/recipes.md +324 -0
  50. package/istm-animate/references/review.md +112 -0
  51. package/istm-animate/references/standards.md +187 -0
  52. package/istm-animate/references/vocabulary.md +173 -0
  53. package/istm-architecture/SKILL.md +10 -1
  54. package/istm-awwward-designer/SKILL.md +28 -20
  55. package/istm-design/SKILL.md +31 -58
  56. package/istm-design/core/design-audit/SKILL.md +248 -0
  57. package/istm-design/core/desktop-principles/SKILL.md +363 -0
  58. package/istm-design/core/desktop-principles/references/keyboard-patterns.md +137 -0
  59. package/istm-design/core/desktop-principles/references/multi-window.md +105 -0
  60. package/istm-design/core/mobile-principles/SKILL.md +289 -0
  61. package/istm-design/core/mobile-principles/references/accessibility-mobile.md +175 -0
  62. package/istm-design/core/mobile-principles/references/gestures-deep.md +220 -0
  63. package/istm-design/core/ui-ux-pro-max/SKILL.md +392 -0
  64. package/istm-design/core/ui-ux-pro-max/UPSTREAM.md +23 -0
  65. package/istm-design/core/ui-ux-pro-max/data/app-interface.csv +31 -0
  66. package/istm-design/core/ui-ux-pro-max/data/charts.csv +26 -0
  67. package/istm-design/core/ui-ux-pro-max/data/colors.csv +193 -0
  68. package/istm-design/core/ui-ux-pro-max/data/google-fonts.csv +1924 -0
  69. package/istm-design/core/ui-ux-pro-max/data/icons.csv +106 -0
  70. package/istm-design/core/ui-ux-pro-max/data/landing.csv +35 -0
  71. package/istm-design/core/ui-ux-pro-max/data/motion.csv +17 -0
  72. package/istm-design/core/ui-ux-pro-max/data/products.csv +193 -0
  73. package/istm-design/core/ui-ux-pro-max/data/react-performance.csv +45 -0
  74. package/istm-design/core/ui-ux-pro-max/data/stacks/angular.csv +51 -0
  75. package/istm-design/core/ui-ux-pro-max/data/stacks/astro.csv +54 -0
  76. package/istm-design/core/ui-ux-pro-max/data/stacks/avalonia.csv +57 -0
  77. package/istm-design/core/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
  78. package/istm-design/core/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
  79. package/istm-design/core/ui-ux-pro-max/data/stacks/javafx.csv +76 -0
  80. package/istm-design/core/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -0
  81. package/istm-design/core/ui-ux-pro-max/data/stacks/laravel.csv +51 -0
  82. package/istm-design/core/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
  83. package/istm-design/core/ui-ux-pro-max/data/stacks/nuxt-ui.csv +71 -0
  84. package/istm-design/core/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
  85. package/istm-design/core/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
  86. package/istm-design/core/ui-ux-pro-max/data/stacks/react.csv +54 -0
  87. package/istm-design/core/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
  88. package/istm-design/core/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
  89. package/istm-design/core/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
  90. package/istm-design/core/ui-ux-pro-max/data/stacks/threejs.csv +54 -0
  91. package/istm-design/core/ui-ux-pro-max/data/stacks/uno.csv +60 -0
  92. package/istm-design/core/ui-ux-pro-max/data/stacks/uwp.csv +56 -0
  93. package/istm-design/core/ui-ux-pro-max/data/stacks/vue.csv +50 -0
  94. package/istm-design/core/ui-ux-pro-max/data/stacks/winui.csv +60 -0
  95. package/istm-design/core/ui-ux-pro-max/data/stacks/wpf.csv +57 -0
  96. package/istm-design/core/ui-ux-pro-max/data/styles.csv +85 -0
  97. package/istm-design/core/ui-ux-pro-max/data/typography.csv +75 -0
  98. package/istm-design/core/ui-ux-pro-max/data/ui-reasoning.csv +162 -0
  99. package/istm-design/core/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
  100. package/istm-design/core/ui-ux-pro-max/references/pro-rules.md +109 -0
  101. package/istm-design/core/ui-ux-pro-max/references/quick-reference.md +240 -0
  102. package/istm-design/core/ui-ux-pro-max/scripts/core.py +464 -0
  103. package/istm-design/core/ui-ux-pro-max/scripts/design_system.py +1371 -0
  104. package/istm-design/core/ui-ux-pro-max/scripts/search.py +162 -0
  105. package/istm-design/core/ui-ux-pro-max/scripts/tests/test_core.py +134 -0
  106. package/istm-design/core/ui-ux-pro-max/scripts/validate_data.py +114 -0
  107. package/istm-design/references/apple-design.md +282 -0
  108. package/istm-design/references/generation-guide.md +209 -0
  109. package/istm-design/references/pick-ui-library.md +77 -0
  110. package/istm-design/references/picker.md +197 -0
  111. package/istm-design/references/prototype.md +90 -0
  112. package/istm-design/references/schema.md +366 -0
  113. package/istm-workflow/istm-audit/SKILL.md +7 -7
  114. package/istm-workflow/istm-audit/agent-prompt.md +20 -20
  115. package/istm-workflow/istm-audit/modes/area.md +1 -1
  116. package/istm-workflow/istm-audit/modes/greenfield.md +4 -4
  117. package/istm-workflow/istm-audit/modes/tool-skills.md +1 -1
  118. package/istm-workflow/istm-check/SKILL.md +10 -10
  119. package/istm-workflow/istm-check/modes/review.md +9 -9
  120. package/istm-workflow/istm-check/modes/verify.md +19 -19
  121. package/istm-workflow/istm-check/review-agent-prompt.md +2 -2
  122. package/istm-workflow/istm-check/review-guide.md +4 -4
  123. package/istm-workflow/istm-craft/SKILL.md +20 -11
  124. package/istm-workflow/istm-craft/agent-modes/architecture.md +1 -1
  125. package/istm-workflow/istm-craft/agent-prompt.md +8 -8
  126. package/istm-workflow/istm-craft/internal/after-subagent.md +11 -11
  127. package/istm-workflow/istm-craft/internal/design-conversation.md +9 -9
  128. package/istm-workflow/istm-craft/internal/tool-discovery.md +2 -2
  129. package/istm-workflow/istm-craft/spec-template.md +18 -18
  130. package/istm-workflow/istm-debug/SKILL.md +6 -6
  131. package/istm-workflow/istm-develop/SKILL.md +31 -16
  132. package/istm-workflow/istm-develop/checklist.md +1 -1
  133. package/istm-workflow/istm-develop/flow/build.md +21 -21
  134. package/istm-workflow/istm-develop/flow/git.md +4 -4
  135. package/istm-workflow/istm-develop/logical-guide.md +5 -5
  136. package/istm-workflow/istm-develop/ui/implementation.md +2 -2
  137. package/istm-workflow/istm-develop/ui-guide.md +3 -3
  138. package/istm-workflow/istm-document/SKILL.md +6 -6
  139. package/istm-workflow/istm-document/templates/postmortem.md +1 -1
  140. package/istm-workflow/istm-scope/SKILL.md +20 -20
  141. package/istm-workflow/istm-scope/modes/add.md +1 -1
  142. package/istm-workflow/istm-scope/modes/plan-brownfield.md +2 -2
  143. package/istm-workflow/istm-scope/modes/plan-greenfield.md +4 -4
  144. package/istm-workflow/istm-scope/modes/plan-monorepo.md +3 -3
  145. package/istm-workflow/istm-scope/modes/plan.md +16 -16
  146. package/istm-workflow/istm-scope/modes/replan.md +2 -2
  147. package/istm-workflow/istm-scope/scope-template.md +29 -29
  148. package/istm-workflow/istm-sync/SKILL.md +37 -25
  149. package/istm-workflow/istm-sync/agent-prompt.md +37 -19
  150. package/istm-workflow/istm-test/SKILL.md +12 -12
  151. package/istm-workflow/istm-test/modes/setup.md +6 -6
  152. package/istm-workflow/istm-test/writing-guide.md +1 -1
  153. package/package.json +1 -1
@@ -0,0 +1,281 @@
1
+ # Shared Element Transitions in Compose
2
+
3
+ `SharedTransitionLayout` morphs an element's bounds, position, and (with `sharedBounds`) shape between two destinations. The receiver lays out both states in the same coordinate space and interpolates between them. Stable since Compose 1.7 - this is the canonical hero / detail / picture-in-picture pattern.
4
+
5
+ ---
6
+
7
+ ## Setup
8
+
9
+ The whole machinery lives behind two scopes:
10
+
11
+ - `SharedTransitionScope` - exposes the `Modifier.sharedElement(...)` and `Modifier.sharedBounds(...)` extensions.
12
+ - `AnimatedVisibilityScope` - the visibility context that drives the in/out transition (every `AnimatedContent` content lambda is one; every `composable<Route>` block in `NavHost` exposes one).
13
+
14
+ Wrap the screen swap in `SharedTransitionLayout` and pass both scopes down. `Modifier.sharedElement` is for elements that keep the same shape and aspect (an image moving across screens). `Modifier.sharedBounds` is for content whose size, shape, or content meaningfully changes (a card expanding into a full panel, a button morphing into a header).
15
+
16
+ Compose 1.7+ baseline. With androidx.navigation 2.8+ on Compose, scopes are exposed directly inside `composable<Route>` lambdas.
17
+
18
+ ---
19
+
20
+ ## Recipe 1 - Card to Detail
21
+
22
+ ```kotlin
23
+ sealed interface Screen {
24
+ data object List : Screen
25
+ data class Detail(val item: Item) : Screen
26
+ }
27
+
28
+ @Composable
29
+ fun App() {
30
+ var current by remember { mutableStateOf<Screen>(Screen.List) }
31
+
32
+ SharedTransitionLayout {
33
+ AnimatedContent(
34
+ targetState = current,
35
+ label = "screen",
36
+ transitionSpec = { fadeIn() togetherWith fadeOut() },
37
+ ) { screen ->
38
+ when (screen) {
39
+ Screen.List -> ListScreen(
40
+ onOpen = { current = Screen.Detail(it) },
41
+ sts = this@SharedTransitionLayout,
42
+ avs = this@AnimatedContent,
43
+ )
44
+ is Screen.Detail -> DetailScreen(
45
+ item = screen.item,
46
+ onBack = { current = Screen.List },
47
+ sts = this@SharedTransitionLayout,
48
+ avs = this@AnimatedContent,
49
+ )
50
+ }
51
+ }
52
+ }
53
+ }
54
+
55
+ @Composable
56
+ fun ListScreen(
57
+ onOpen: (Item) -> Unit,
58
+ sts: SharedTransitionScope,
59
+ avs: AnimatedVisibilityScope,
60
+ ) {
61
+ LazyColumn { items(items, key = { it.id }) { item ->
62
+ with(sts) {
63
+ Card(
64
+ onClick = { onOpen(item) },
65
+ modifier = Modifier.sharedBounds(
66
+ sharedContentState = rememberSharedContentState("card-${item.id}"),
67
+ animatedVisibilityScope = avs,
68
+ ),
69
+ ) {
70
+ Image(
71
+ painter = item.painter,
72
+ contentDescription = null,
73
+ modifier = Modifier.sharedElement(
74
+ state = rememberSharedContentState("image-${item.id}"),
75
+ animatedVisibilityScope = avs,
76
+ ),
77
+ )
78
+ Text(item.title)
79
+ }
80
+ }
81
+ } }
82
+ }
83
+
84
+ @Composable
85
+ fun DetailScreen(
86
+ item: Item,
87
+ onBack: () -> Unit,
88
+ sts: SharedTransitionScope,
89
+ avs: AnimatedVisibilityScope,
90
+ ) {
91
+ with(sts) {
92
+ Column(
93
+ modifier = Modifier.sharedBounds(
94
+ sharedContentState = rememberSharedContentState("card-${item.id}"),
95
+ animatedVisibilityScope = avs,
96
+ ),
97
+ ) {
98
+ Image(
99
+ painter = item.painter,
100
+ contentDescription = null,
101
+ modifier = Modifier
102
+ .fillMaxWidth()
103
+ .height(360.dp)
104
+ .sharedElement(
105
+ state = rememberSharedContentState("image-${item.id}"),
106
+ animatedVisibilityScope = avs,
107
+ ),
108
+ )
109
+ Text(item.title, style = MaterialTheme.typography.headlineLarge)
110
+ Text(item.description)
111
+ }
112
+ }
113
+ }
114
+ ```
115
+
116
+ The card outer shape uses `sharedBounds` (different size/shape between list and detail). The image uses `sharedElement` (same content, just translated and scaled). Keys are stable per item id.
117
+
118
+ ---
119
+
120
+ ## Recipe 2 - Image Hero
121
+
122
+ A photo grid that opens into a full-bleed photo detail. Same key on the `Image` composable on both sides; the framework interpolates the bounds.
123
+
124
+ ```kotlin
125
+ // Grid:
126
+ Image(
127
+ painter = item.painter,
128
+ contentDescription = null,
129
+ modifier = Modifier
130
+ .aspectRatio(1f)
131
+ .sharedElement(
132
+ state = rememberSharedContentState("photo-${item.id}"),
133
+ animatedVisibilityScope = avs,
134
+ boundsTransform = { _, _ ->
135
+ spring(stiffness = Spring.StiffnessMediumLow, dampingRatio = 0.85f)
136
+ },
137
+ ),
138
+ )
139
+
140
+ // Detail:
141
+ Image(
142
+ painter = item.painter,
143
+ contentDescription = null,
144
+ contentScale = ContentScale.Fit,
145
+ modifier = Modifier
146
+ .fillMaxWidth()
147
+ .sharedElement(
148
+ state = rememberSharedContentState("photo-${item.id}"),
149
+ animatedVisibilityScope = avs,
150
+ ),
151
+ )
152
+ ```
153
+
154
+ `boundsTransform` (declared on the source side typically, both is fine) controls the spring on the bounds interpolation. Default is a snappy spring; soften for a more cinematic feel.
155
+
156
+ ---
157
+
158
+ ## Recipe 3 - Tab Header Morph in `HorizontalPager`
159
+
160
+ A header strip whose accent pill morphs as the user swipes between tabs. `SharedTransitionLayout` wraps the pager; each page declares its own `sharedElement` with the SAME key for the morphing element.
161
+
162
+ ```kotlin
163
+ SharedTransitionLayout {
164
+ HorizontalPager(state = pagerState) { pageIndex ->
165
+ AnimatedContent(
166
+ targetState = pageIndex,
167
+ label = "tabPage",
168
+ ) { page ->
169
+ Column {
170
+ Box(
171
+ modifier = Modifier
172
+ .height(48.dp)
173
+ .background(palette[page], RoundedCornerShape(24.dp))
174
+ .sharedElement(
175
+ state = rememberSharedContentState("tab-pill"),
176
+ animatedVisibilityScope = this@AnimatedContent,
177
+ ),
178
+ )
179
+ TabContent(page)
180
+ }
181
+ }
182
+ }
183
+ }
184
+ ```
185
+
186
+ Note: real-world tab bars usually do this with a single backing layout reading the pager's settled offset directly - shared elements shine when the morph crosses screen boundaries, not strictly within a single fixed layout.
187
+
188
+ ---
189
+
190
+ ## `rememberSharedContentState` - Keys Discipline
191
+
192
+ **Rule:** keys must be stable AND unique per logical element across the screens that share it.
193
+
194
+ ```kotlin
195
+ // BAD - index changes when the list reorders, transition mistargets
196
+ items.forEachIndexed { i, item ->
197
+ Image(modifier = Modifier.sharedElement(rememberSharedContentState("hero-$i"), avs))
198
+ }
199
+ ```
200
+
201
+ ```kotlin
202
+ // GOOD - id-based
203
+ items.forEach { item ->
204
+ Image(modifier = Modifier.sharedElement(rememberSharedContentState("hero-${item.id}"), avs))
205
+ }
206
+ ```
207
+
208
+ If the same screen contains multiple shared elements, namespace them: `"image-${item.id}"`, `"title-${item.id}"`. Ambiguous keys = wrong element gets matched and you get a teleporting image.
209
+
210
+ ---
211
+
212
+ ## Bound Modifiers and `sharedBounds` Knobs
213
+
214
+ `Modifier.sharedBounds(...)` accepts:
215
+
216
+ - `enter` / `exit`: `EnterTransition` / `ExitTransition` for content INSIDE the morphing bounds (default `fadeIn()` / `fadeOut()`).
217
+ - `boundsTransform`: spring/tween for the bounds interpolation itself.
218
+ - `resizeMode`: `ScaleToBounds(contentScale, alignment)` (default - scales content to match bounds, useful when content shape matches) or `RemeasureToBounds` (re-measures content at every step, useful for text reflow).
219
+ - `clipInOverlayDuringTransition`: an `OverlayClip(shape)` applied while the element is in the overlay. Use a rounded shape that matches your destination card to avoid hard rectangle flashes.
220
+ - `placeHolderSize`: how the source slot reserves space during the transition (`PlaceHolderSize.contentSize` by default, `PlaceHolderSize.animatedSize` to animate the gap).
221
+
222
+ Quick template for a card-to-screen morph:
223
+
224
+ ```kotlin
225
+ Modifier.sharedBounds(
226
+ sharedContentState = rememberSharedContentState("card-${id}"),
227
+ animatedVisibilityScope = avs,
228
+ enter = fadeIn(tween(150)),
229
+ exit = fadeOut(tween(80)),
230
+ resizeMode = SharedTransitionScope.ResizeMode.RemeasureToBounds,
231
+ clipInOverlayDuringTransition = OverlayClip(RoundedCornerShape(24.dp)),
232
+ )
233
+ ```
234
+
235
+ ---
236
+
237
+ ## Compose Navigation Integration
238
+
239
+ With androidx.navigation 2.8+ for Compose, scopes are accessible directly inside `composable<Route>` lambdas via `LocalNavAnimatedVisibilityScope` and a `SharedTransitionLayout` wrapping the `NavHost`.
240
+
241
+ ```kotlin
242
+ SharedTransitionLayout {
243
+ NavHost(navController, startDestination = HomeRoute) {
244
+ composable<HomeRoute> {
245
+ HomeScreen(
246
+ sts = this@SharedTransitionLayout,
247
+ avs = this, // AnimatedVisibilityScope
248
+ onOpen = { id -> navController.navigate(DetailRoute(id)) },
249
+ )
250
+ }
251
+ composable<DetailRoute> { backStackEntry ->
252
+ val args: DetailRoute = backStackEntry.toRoute()
253
+ DetailScreen(
254
+ id = args.id,
255
+ sts = this@SharedTransitionLayout,
256
+ avs = this,
257
+ )
258
+ }
259
+ }
260
+ }
261
+ ```
262
+
263
+ Pass `sts` and `avs` exactly as you would inside a manual `AnimatedContent`. The `composable` lambda IS an `AnimatedVisibilityScope`. If you ship Compose Navigation 3 (stable expected early 2026), the surface is the same - the ergonomics get a bit nicer with type-safe routes already inferred.
264
+
265
+ ---
266
+
267
+ ## Gotchas
268
+
269
+ - **Mismatched keys = no animation.** Silent failure. Verify with Layout Inspector's animation panel; both sides must show the same `SharedContentState`.
270
+ - **Unmounted source.** Don't put a `sharedElement` inside a `LazyColumn` item that may be scrolled off when the transition starts. The framework needs the source slot to be measurable to compute origin bounds. Workaround: scroll to make the source visible before triggering navigation, or use `sharedBounds` on the entire visible row.
271
+ - **Performance.** Each shared element is a render pass through the overlay. Sharing 20+ elements at once tanks frame rate. Share the hero image and the title; let everything else fade.
272
+ - **Z-order during transition.** Shared elements render in the overlay above the rest of the layout. If you have UI that should sit above the morph (top app bar, fab), keep it OUTSIDE `SharedTransitionLayout` or accept the overlap.
273
+ - **Reduced motion.** Wrap shared transitions in a check (see `../SKILL.md` reduced-motion section) and replace with a `snap()` `boundsTransform` and an instant `tween(0)` enter/exit.
274
+
275
+ ---
276
+
277
+ ## Sources
278
+
279
+ - [Android SharedTransitionLayout docs](https://developer.android.com/develop/ui/compose/animation/shared-elements)
280
+ - [skydoves/Orbital](https://github.com/skydoves/Orbital) - shared element transitions library and recipes
281
+ - [androidx.navigation Compose animations](https://developer.android.com/jetpack/androidx/releases/navigation)
@@ -0,0 +1,311 @@
1
+ ---
2
+ name: compose-multiplatform
3
+ description: "Compose Multiplatform / KMP patterns - expect/actual composables, platform-specific code, density and font handling cross-target, iOS/Android/Desktop interop."
4
+ ---
5
+
6
+ # Compose Multiplatform
7
+
8
+ > Compose Multiplatform (CMP) and Kotlin Multiplatform (KMP) patterns for cross-platform UI.
9
+ > Loaded for projects with `org.jetbrains.compose` plugin.
10
+ > Foundation: `../compose-motion/SKILL.md` for animation API; this file covers what's specific to writing one Compose codebase for Android + iOS + Desktop + Web.
11
+
12
+ ---
13
+
14
+ ## KMP vs CMP - quick clarification
15
+
16
+ **KMP** (Kotlin Multiplatform) is the language and build infrastructure: shared Kotlin code compiled to JVM, Native (iOS, macOS, Linux, Windows), and Wasm. **CMP** (Compose Multiplatform) is the UI framework on top of KMP, built by JetBrains as a port of Jetpack Compose. You write a single Compose codebase in `commonMain` that runs on Android, iOS, Desktop (JVM), and Web (Wasm). Platform-specific code lives in `androidMain`, `iosMain`, `desktopMain`, `wasmJsMain` and is wired in via `expect`/`actual` declarations.
17
+
18
+ ---
19
+
20
+ ## Project structure
21
+
22
+ ```
23
+ composeApp/
24
+ ├── src/
25
+ │ ├── commonMain/ ← shared Compose code (most of the app)
26
+ │ │ └── kotlin/
27
+ │ ├── androidMain/ ← Android-specific (uses Activity, Context)
28
+ │ ├── iosMain/ ← iOS-specific (uses UIKit/UIView interop)
29
+ │ ├── desktopMain/ ← JVM desktop (uses java.awt/swing if needed)
30
+ │ └── wasmJsMain/ ← Wasm web target
31
+ ├── build.gradle.kts
32
+ iosApp/ ← Xcode project consuming the generated framework
33
+ androidApp/ ← Android Application module (often merged into composeApp)
34
+ ```
35
+
36
+ The `commonMain` folder should hold 80-95% of your code in a well-architected CMP project. If `iosMain` or `androidMain` start growing past a few hundred lines, you're probably leaking platform concerns into UI logic that could stay shared.
37
+
38
+ ---
39
+
40
+ ## `expect`/`actual` pattern
41
+
42
+ The KMP escape hatch when you genuinely need different implementations per target. Declare the contract once in `commonMain`, implement it once per target.
43
+
44
+ ```kotlin
45
+ // commonMain
46
+ expect fun openShareSheet(text: String)
47
+
48
+ // androidMain
49
+ actual fun openShareSheet(text: String) {
50
+ val intent = Intent(Intent.ACTION_SEND).apply {
51
+ type = "text/plain"
52
+ putExtra(Intent.EXTRA_TEXT, text)
53
+ }
54
+ context.startActivity(Intent.createChooser(intent, null))
55
+ }
56
+
57
+ // iosMain
58
+ actual fun openShareSheet(text: String) {
59
+ val activityVC = UIActivityViewController(
60
+ activityItems = listOf(text),
61
+ applicationActivities = null
62
+ )
63
+ UIApplication.sharedApplication.keyWindow
64
+ ?.rootViewController
65
+ ?.presentViewController(activityVC, true, null)
66
+ }
67
+ ```
68
+
69
+ `expect`/`actual` works for top-level functions, classes, type aliases, and properties. The signature in `actual` must match exactly, including modifiers and default values.
70
+
71
+ ---
72
+
73
+ ## `expect`/`actual` for composables
74
+
75
+ Composables follow the same rules. Useful when a feature needs a platform-specific Compose API (Android `RuntimeShader`, iOS `UIKitView`, Desktop `SwingPanel`).
76
+
77
+ ```kotlin
78
+ // commonMain
79
+ @Composable
80
+ expect fun PlatformBlur(modifier: Modifier = Modifier, content: @Composable () -> Unit)
81
+
82
+ // androidMain (uses RuntimeShader on Android 13+)
83
+ @Composable
84
+ actual fun PlatformBlur(modifier: Modifier, content: @Composable () -> Unit) {
85
+ Box(modifier.graphicsLayer { renderEffect = blurEffect }) { content() }
86
+ }
87
+
88
+ // iosMain (uses UIVisualEffectView via UIKitView)
89
+ @Composable
90
+ actual fun PlatformBlur(modifier: Modifier, content: @Composable () -> Unit) {
91
+ Box(modifier) {
92
+ UIKitView(
93
+ factory = { UIVisualEffectView(effect = UIBlurEffect.systemMaterial()) },
94
+ modifier = Modifier.matchParentSize()
95
+ )
96
+ content()
97
+ }
98
+ }
99
+ ```
100
+
101
+ Rule: `expect` composables should be the exception, not the rule. Most "platform feel" differences can be tuned via tokens (colors, corner radii, spring stiffness) in `commonMain`, not via separate code paths.
102
+
103
+ ---
104
+
105
+ ## `LocalDensity` cross-platform
106
+
107
+ On Android, `LocalDensity.current.density` reflects the device DPI bucket (1.0, 1.5, 2.0, 3.0...). On iOS, density is computed from `UIScreen.scale` (typically 2.0 or 3.0 on Retina). On Desktop, density depends on the screen scaling factor (1.0 by default; 2.0 on Retina-class displays; user-configurable on Windows). On Wasm, density follows `window.devicePixelRatio`.
108
+
109
+ Don't hardcode `Dp` to pixel ratios; trust `Dp` and `LocalDensity` to handle conversion. If you need an exact pixel value (e.g., for a `Canvas` draw operation), do the conversion explicitly:
110
+
111
+ ```kotlin
112
+ val density = LocalDensity.current
113
+ val pxValue = with(density) { 16.dp.toPx() }
114
+ ```
115
+
116
+ Avoid reading `density` inside hot loops; cache the conversion.
117
+
118
+ ---
119
+
120
+ ## `LocalConfiguration` and platform-aware UI
121
+
122
+ `LocalConfiguration.current` is **Android-only** and lives in `androidMain`. For CMP, prefer the cross-platform alternatives:
123
+
124
+ - `LocalWindowInfo.current.containerSize` - the window/screen size as `IntSize`, available in `commonMain`.
125
+ - `LocalDensity.current` - density, available in `commonMain`.
126
+ - `LocalLayoutDirection.current` - LTR / RTL.
127
+ - `BoxWithConstraints { ... }` - read `maxWidth` / `maxHeight` directly inside layout.
128
+
129
+ If you need real device characteristics (orientation, idiom, model), wrap the access in `expect`/`actual` and pass a typed object like `PlatformInfo` to the common layer.
130
+
131
+ ---
132
+
133
+ ## Fonts cross-platform via Compose Resources
134
+
135
+ `org.jetbrains.compose.resources` is the shared resources plugin. Drop fonts in `commonMain/composeResources/font/`, and the Gradle plugin generates a typed `Res` accessor.
136
+
137
+ ```
138
+ composeApp/src/commonMain/composeResources/
139
+ ├── font/
140
+ │ ├── Inter-Regular.ttf
141
+ │ └── Inter-Bold.ttf
142
+ ├── drawable/
143
+ │ └── logo.svg
144
+ └── values/
145
+ ├── strings.xml ← default locale
146
+ └── strings.fr.xml ← French overrides
147
+ ```
148
+
149
+ Usage in `commonMain`:
150
+
151
+ ```kotlin
152
+ import myproject.composeapp.generated.resources.Inter_Regular
153
+ import myproject.composeapp.generated.resources.Inter_Bold
154
+ import myproject.composeapp.generated.resources.Res
155
+
156
+ val InterFamily = FontFamily(
157
+ Font(Res.font.Inter_Regular, FontWeight.Normal),
158
+ Font(Res.font.Inter_Bold, FontWeight.Bold),
159
+ )
160
+
161
+ Text("Hello", fontFamily = InterFamily)
162
+ ```
163
+
164
+ Same pattern for `Res.drawable.logo` (image), `Res.string.app_name` (localized string via `stringResource(...)`), `Res.file.config` (raw bytes via `Res.readBytes(...)`).
165
+
166
+ ---
167
+
168
+ ## iOS interop with SwiftUI
169
+
170
+ CMP produces a `UIViewController` you can drop into a SwiftUI app. KMP generates a top-level Kotlin function (commonly named `MainViewController()` or `ComposeUIViewController { ... }`) that returns a `UIViewController`. Wrap it with `UIViewControllerRepresentable`.
171
+
172
+ ```kotlin
173
+ // iosMain/kotlin/main.ios.kt
174
+ fun MainViewController(): UIViewController = ComposeUIViewController {
175
+ AppContent() // commonMain composable
176
+ }
177
+ ```
178
+
179
+ ```swift
180
+ // iOS app target
181
+ import SwiftUI
182
+ import ComposeApp // KMP-generated framework
183
+
184
+ struct ComposeContent: UIViewControllerRepresentable {
185
+ func makeUIViewController(context: Context) -> UIViewController {
186
+ Main_iosKt.MainViewController()
187
+ }
188
+ func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
189
+ }
190
+
191
+ struct ContentView: View {
192
+ var body: some View { ComposeContent().ignoresSafeArea() }
193
+ }
194
+ ```
195
+
196
+ The Kotlin function name gets mangled to `Main_iosKt.MainViewController()` because the file is `main.ios.kt`. Check the generated framework headers if the symbol name surprises you.
197
+
198
+ ---
199
+
200
+ ## Android entry point
201
+
202
+ No interop ceremony on Android. The Activity hosts the common composable directly via `setContent { ... }`.
203
+
204
+ ```kotlin
205
+ // androidApp/src/main/kotlin/MainActivity.kt
206
+ class MainActivity : ComponentActivity() {
207
+ override fun onCreate(savedInstanceState: Bundle?) {
208
+ super.onCreate(savedInstanceState)
209
+ setContent {
210
+ AppContent() // commonMain composable
211
+ }
212
+ }
213
+ }
214
+ ```
215
+
216
+ If you need to pass `Context` or `Activity` into `commonMain`, expose it via a DI graph or an `expect class PlatformContext` in `commonMain` with `actual class PlatformContext(val context: Context)` in `androidMain`.
217
+
218
+ ---
219
+
220
+ ## Embedding SwiftUI/UIKit inside a Compose iOS view (the reverse direction)
221
+
222
+ Use `UIKitView` for a `UIView` factory or `UIKitViewController` for a `UIViewController` factory.
223
+
224
+ ```kotlin
225
+ // iosMain
226
+ UIKitView(
227
+ factory = {
228
+ UISwitch().apply {
229
+ addTarget(target, action = NSSelectorFromString("onToggle:"), forControlEvents = UIControlEventValueChanged)
230
+ }
231
+ },
232
+ modifier = Modifier.size(48.dp, 32.dp)
233
+ )
234
+ ```
235
+
236
+ For SwiftUI views: wrap them in a `UIHostingController` exposed via a Swift `@objc` bridge function, then call from Kotlin via the generated headers (cinterop). See `references/cmp-interop.md` for the full pattern.
237
+
238
+ ---
239
+
240
+ ## Animation cross-platform
241
+
242
+ All animation APIs (`animate*AsState`, `AnimatedVisibility`, `updateTransition`, `SharedTransitionLayout`) work identically across targets in CMP 1.7+. Spring tuning written in `commonMain` produces the same physics on Android and iOS. Gestures (`Modifier.draggable`, `Modifier.pointerInput`) work cross-platform with the same API surface.
243
+
244
+ The animation primer lives in `../compose-motion/SKILL.md`. Cross-platform deltas to keep in mind:
245
+ - iOS first-frame is slower (Skia bootstrap); a 200ms enter animation feels tighter on Android, slightly delayed on iOS cold start.
246
+ - Wasm motion can stutter on first frame (JIT warmup); pre-warm critical paths or hide motion until interactive.
247
+
248
+ ---
249
+
250
+ ## What does NOT work (gotchas)
251
+
252
+ - **Drawer state on iOS**: native `ModalNavigationDrawer` swipe-to-open from the leading edge conflicts with iOS's back-swipe gesture. Use a button trigger or move the swipe area inward 30dp+.
253
+ - **`LayoutDirection.Rtl` quirks**: Android handles RTL natively, iOS Compose had bugs in 1.6 (text alignment, padding inversions). Improved in 1.7+ but verify with real Arabic/Hebrew strings.
254
+ - **Soft keyboard handling**: `imePadding()` works on Android out of the box. On iOS Compose 1.6+, it requires `IOSKeyboardEventListener` setup or a `WindowInsets` observer wired through the platform layer.
255
+ - **`Color.parseHex(...)`** does not exist in Compose. Use `Color(0xFFRRGGBB)` or write a tiny extension.
256
+ - **System fonts on iOS via Compose**: do not fallback to `FontFamily.SansSerif` and expect SF Pro. Compose on iOS ships its own font fallback chain. Either bundle SF Pro via Compose Resources (license-permitting) or use `UIKitView` to drop a native `UILabel` for system-font text.
257
+ - **Animations on Web (Wasm)**: heavier startup, occasional first-frame stutter; profile with browser devtools and lazy-load heavy animation graphs.
258
+ - **`java.util.UUID`, `java.io.File`** and other JVM-only APIs are forbidden in `commonMain` if you ship to iOS or Wasm. Use `kotlinx.uuid`, `kotlinx-io`, or the `okio` multiplatform port.
259
+
260
+ ---
261
+
262
+ ## CMP version notes
263
+
264
+ - Compose Multiplatform 1.7 stable: `SharedTransitionLayout` cross-platform, improved iOS keyboard handling, lifecycle observability via `LocalLifecycleOwner` on iOS.
265
+ - Kotlin 2.0+ required (K2 compiler).
266
+ - Some Material 3 components have platform-specific look (e.g., `Switch` on iOS auto-renders with iOS-style proportions; `DatePicker` stays Material across all targets).
267
+ - `compose-multiplatform-resources` plugin is the standard for assets; the older `moko-resources` is no longer recommended for new projects.
268
+
269
+ ---
270
+
271
+ ## Performance considerations
272
+
273
+ - **iOS first-frame** is slower than Android (Skia bootstrapping ~150-300ms cold). Keep your splash visible until the first composition emits, or pre-warm with a transparent root composable.
274
+ - **Wasm bundle size**: aim for <2MB compressed. Tree-shake heavy deps, lazy-load secondary screens via `kotlinx.coroutines` deferred composition, and inspect the `.wasm` output in `wasmJsBrowserDistribution`.
275
+ - **Desktop**: cold start is fast on JVM; AOT compilation via Kotlin/Native is overkill for desktop unless you need a single-file binary.
276
+ - **Android**: same baseline as Jetpack Compose - profile with the Compose compiler stability metrics and `Layout Inspector` recomposition counts.
277
+
278
+ ---
279
+
280
+ ## Anti-Patterns
281
+
282
+ | BAD | GOOD | Why |
283
+ |---|---|---|
284
+ | Reflection trick or `System.getProperty("os.name")` to detect platform inside `commonMain` | `expect`/`actual` with a typed `Platform` object | Reflection breaks on Wasm/Native; `expect`/`actual` is the contract the compiler enforces |
285
+ | Assuming Android `Context` is reachable in `commonMain` | Inject a typed dependency via `expect class PlatformContext` or a DI scope | `Context` does not exist on iOS/Desktop/Wasm; the code will not compile for those targets |
286
+ | Hardcoding Material colors that look great on Android but jarring on iOS | Define a `commonMain` design system, then optionally adjust 2-3 tokens via `actual` | Cross-platform consistency is good, but iOS users notice when a Material blue feels alien on iPhone |
287
+ | `LaunchedEffect(Unit) { while(true) { delay(16); ... } }` in `commonMain` | `rememberInfiniteTransition()` or scope to lifecycle events | Tight coroutine loops drain battery on iOS; infinite transitions pause when offscreen |
288
+
289
+ ---
290
+
291
+ ## Quick Reference: Loading Sub-skills
292
+
293
+ | Need | Load |
294
+ |---|---|
295
+ | iOS / Android interop deep-dive | `references/cmp-interop.md` |
296
+ | Per-platform behavior catalog | `references/cmp-platform-quirks.md` |
297
+ | Animation API | `../compose-motion/SKILL.md` |
298
+ | Advanced graphics (M3 Expressive, AGSL on Android only) | `../compose-graphics/SKILL.md` |
299
+ | iOS-side native interop with SwiftUI | `../swiftui-motion/SKILL.md` (when target is iOS and SwiftUI native blend wanted) |
300
+ | Mobile UX context | `../mobile-principles/SKILL.md` |
301
+ | Desktop UX context | `../desktop-principles/SKILL.md` |
302
+ | Foundation | `../motion-principles/SKILL.md` |
303
+
304
+ ---
305
+
306
+ ## Sources
307
+
308
+ - [Meet-Miyani/compose-skill](https://github.com/Meet-Miyani/compose-skill) (KMP/CMP comprehensive)
309
+ - [JetBrains Compose Multiplatform](https://www.jetbrains.com/lp/compose-multiplatform/)
310
+ - [Compose Multiplatform docs](https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-multiplatform.html)
311
+ - [skydoves/Orbital](https://github.com/skydoves/Orbital) (KMP-aware shared transitions)