compose-expert
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseInstallation notice: This skill is now distributed as a plugin. If you copied files intomanually, you are on an unmaintained install path and will not receive updates. Migrate via:~/.claude/skills//plugin marketplace add aldefy/compose-skill /plugin install compose-expertSee MIGRATION.md for Codex and Copilot CLI instructions. This banner will remain through v2.x and escalate in v3.0.
安装通知: 本技能现已以插件形式分发。 如果你之前手动将文件复制到了目录,那么你使用的是 无人维护的安装路径,将无法收到更新。请通过以下命令迁移:~/.claude/skills//plugin marketplace add aldefy/compose-skill /plugin install compose-expertCodex和Copilot CLI的迁移说明请参见MIGRATION.md。 本提示横幅将在v2.x版本期间保留,并在v3.0中升级提示级别。
When this skill applies
技能触发场景
The frontmatter is intentionally short to satisfy Codex / Copilot
CLI's 1024-character cap on that field (see issue #12). The full trigger surface
lives here so it stays available to Claude after the skill loads.
description:前置元数据中的字段刻意保持简短,以满足Codex / Copilot CLI对该字段1024字符的限制(参见issue #12)。完整的触发范围放在此处,以便技能加载后Claude仍可访问。
description:Compose API mentions
Compose API相关触发词
@ComposableremembermutableStateOfderivedStateOfrememberSaveableLaunchedEffectDisposableEffectSideEffectrememberCoroutineScopeScaffoldNavHostNavControllerMaterialThemeColorSchemeTypographyLazyColumnLazyRowLazyVerticalGridHorizontalPagerModifierModifier.NoderecompositionCompositionLocalStylestyleableMutableStyleStateMaterial 3 ExpressiveM3 ExpressiveMaterialExpressiveThemeButtonGroupSplitButtonFloatingActionButtonMenuLoadingIndicatorHorizontalFloatingToolbarNavDisplayNavKeyrememberNavBackStackNavigableListDetailPaneScaffold@ComposableremembermutableStateOfderivedStateOfrememberSaveableLaunchedEffectDisposableEffectSideEffectrememberCoroutineScopeScaffoldNavHostNavControllerMaterialThemeColorSchemeTypographyLazyColumnLazyRowLazyVerticalGridHorizontalPagerModifierModifier.NoderecompositionCompositionLocalStylestyleableMutableStyleStateMaterial 3 ExpressiveM3 ExpressiveMaterialExpressiveThemeButtonGroupSplitButtonFloatingActionButtonMenuLoadingIndicatorHorizontalFloatingToolbarNavDisplayNavKeyrememberNavBackStackNavigableListDetailPaneScaffoldCompose Multiplatform / KMP
Compose Multiplatform / KMP相关触发词
Compose MultiplatformCMPKMPcommonMainexpectactualComposeUIViewControllerWindowUIKitViewComposeViewportRes.drawableRes.stringSkikoMainCompose MultiplatformCMPKMPcommonMainexpectactualComposeUIViewControllerWindowUIKitViewComposeViewportRes.drawableRes.stringSkikoMainAndroid TV
Android TV相关触发词
tv-materialtv-foundationCarouselNavigationDrawerD-padfocus indicationFocusRequester10-foot UIliving roomtv composeAndroid TVGoogle TVleanback migrationtv-materialtv-foundationCarouselNavigationDrawerD-padfocus indicationFocusRequester10-foot UIliving roomtv composeAndroid TVGoogle TVleanback migrationPaging 3
Paging 3相关触发词
PagingSourcePagerPagingConfigPagingDataLazyPagingItemscollectAsLazyPagingItemsRemoteMediatorLoadStateasSnapshotTestPagercachedInPagingSourcePagerPagingConfigPagingDataLazyPagingItemscollectAsLazyPagingItemsRemoteMediatorLoadStateasSnapshotTestPagercachedInDesign system / design-to-code
设计系统 / 设计转代码相关触发词
atomic designatomsmoleculesorganismstemplatesdesign tokensdesign systemcomponent libraryreusable componentFigma to Composedesign to composebuild this UIimplement this designspec to coderedlineatomic designatomsmoleculesorganismstemplatesdesign tokensdesign systemcomponent libraryreusable componentFigma to Composedesign to composebuild this UIimplement this designspec to coderedlineCasual phrasing
日常表述触发词
"my compose screen is slow", "my recomposition is broken",
"how do I pass data between screens", "how do I build a TV app",
"Android UI", "Kotlin UI", "compose layout", "compose navigation",
"compose animation", "compose styles", "desktop compose", "iOS compose",
"compose web".
“我的Compose页面卡顿”、“我的recomposition有问题”、
“如何在页面间传递数据”、“如何开发TV应用”、
“Android UI”、“Kotlin UI”、“Compose布局”、“Compose导航”、
“Compose动画”、“Compose样式”、“桌面端Compose”、“iOS端Compose”、
“Compose Web端”。
Review Mode triggers
审查模式触发条件
Any GitHub PR URL matching , or phrases:
"review this PR", "review this diff", "review this code",
"check this code", "check this diff", "what's wrong with this".
On match, follow exclusively.
github.com/.*/pull/\d+references/pr-review.md任何匹配格式的GitHub PR链接,或以下短语:
“review this PR”、“review this diff”、“review this code”、
“check this code”、“check this diff”、“what's wrong with this”。
匹配成功后,将严格遵循中的流程执行。
github.com/.*/pull/\d+references/pr-review.mdSession start
会话开始时
Auto-detect Compose projects on — see .
session_startreferences/auto-init.md在时自动检测Compose项目——参见。
session_startreferences/auto-init.mdQuick Routing
快速路由指引
Use this table first. Match the user's signal to one reference file and read it before
answering. files are supporting evidence — load a file
first, then cite for implementation proof when receipts matter.
source-code/references/*.mdsource-code/请优先使用此表。将用户的需求匹配到对应的参考文件,在回答前先阅读该文件。目录下的文件是支撑证据——请先加载文件,当需要源码凭证时,再引用中的内容作为实现依据。
source-code/references/*.mdsource-code/State, recomposition, side effects
状态、重组与副作用
- ,
remember,rememberSaveablevsmutableStateOf, state hoisting →mutableIntStateOfreferences/state-management.md - ,
derivedStateOf, StateFlow in UI, recomposition scope boundaries →snapshotFlow(secondary:references/state-management.md)references/performance.md - ,
LaunchedEffect,SideEffect,DisposableEffect,rememberUpdatedState→rememberCoroutineScopereferences/side-effects.md - Recomposition frequency, "my screen recomposes too often", stability, /
@Stable, Compose compiler metrics, baseline profiles, strong skipping →@Immutablereferences/performance.md - , ambient values, theming propagation,
CompositionLocalmisuse, custom locals →LocalContextreferences/composition-locals.md
- 、
remember、rememberSaveable与mutableStateOf的区别、状态提升 →mutableIntStateOfreferences/state-management.md - 、
derivedStateOf、UI层StateFlow、重组作用域边界 →snapshotFlow(次要参考:references/state-management.md)references/performance.md - 、
LaunchedEffect、SideEffect、DisposableEffect、rememberUpdatedState→rememberCoroutineScopereferences/side-effects.md - 重组频率、“我的页面重组太频繁”、稳定性、/
@Stable、Compose编译器指标、基准配置文件、强跳过模式 →@Immutablereferences/performance.md - 、环境值、主题传递、
CompositionLocal误用、自定义Local →LocalContextreferences/composition-locals.md
Animation and motion
动画与动效
- ,
animate*AsState,AnimatedVisibility,Crossfade,updateTransition,Animatable→rememberInfiniteTransitionreferences/animation.md - Shared element transitions, gesture-driven animation, , Canvas drawing, custom motion spec →
Modifier.graphicsLayer(secondary:references/animation.mdforreferences/modifiers.md)graphicsLayer - M3 motion tokens, ,
MotionTokens, animation duration tokens, M3 easing curves →MotionSchemereferences/material3-motion.md
- 、
animate*AsState、AnimatedVisibility、Crossfade、updateTransition、Animatable→rememberInfiniteTransitionreferences/animation.md - 共享元素过渡、手势驱动动画、、Canvas绘制、自定义动效规格 →
Modifier.graphicsLayer(次要参考:references/animation.md中references/modifiers.md相关内容)graphicsLayer - M3动效令牌、、
MotionTokens、动画时长令牌、M3缓动曲线 →MotionSchemereferences/material3-motion.md
Layout, lists, modifiers
布局、列表与修饰符
- ,
LazyColumn,LazyRow,LazyVerticalGrid,LazyHorizontalGrid/key,itemKey,contentType, scroll state, sticky headers →LazyListStatereferences/lists-scrolling.md - ,
HorizontalPager,VerticalPager→PagerStatereferences/lists-scrolling.md - Modifier chain ordering, custom layout, ,
Layout, layout modifier, draw modifier,SubcomposeLayout,Painter→Modifier.Nodereferences/modifiers.md
- 、
LazyColumn、LazyRow、LazyVerticalGrid、LazyHorizontalGrid/key、itemKey、contentType、滚动状态、粘性头部 →LazyListStatereferences/lists-scrolling.md - 、
HorizontalPager、VerticalPager→PagerStatereferences/lists-scrolling.md - Modifier链顺序、自定义布局、、
Layout、布局修饰符、绘制修饰符、SubcomposeLayout、Painter→Modifier.Nodereferences/modifiers.md
Navigation
导航
- ,
NavHost, back stack, deep links, type-safeNavControllerroutes, navigation graph, nested graphs →@Serializablereferences/navigation.md - Migrating from Nav 2 to Nav 3, ,
NavDisplay,NavKey,rememberNavBackStackchanges →NavBackStackEntryreferences/navigation-migration.md - Choosing between Nav 2 and Nav 3, type-safe navigation decision, KMP navigation → (secondary:
references/navigation-migration.md)references/navigation.md - Advanced Nav 3: returning results between destinations, auth-gated/conditional navigation, animated/shared-element transitions in , adaptive list-detail (
NavDisplay), multiple/per-tab back stacks →NavigableListDetailPaneScaffoldreferences/navigation-migration.md
- 、
NavHost、返回栈、深链接、类型安全NavController路由、导航图、嵌套导航图 →@Serializablereferences/navigation.md - 从Nav 2迁移到Nav 3、、
NavDisplay、NavKey、rememberNavBackStack变更 →NavBackStackEntryreferences/navigation-migration.md - Nav 2与Nav 3的选型、类型安全导航决策、KMP导航 → (次要参考:
references/navigation-migration.md)references/navigation.md - 进阶Nav 3:目标间返回结果、鉴权/条件导航、中的动画/共享元素过渡、自适应列表详情布局(
NavDisplay)、多返回栈/分标签返回栈 →NavigableListDetailPaneScaffoldreferences/navigation-migration.md
Paging
分页
- ,
PagingSource,PagingDatasetup,Pager,PagingConfig, invalidation →pagingDataFlowreferences/paging.md - ,
LazyPagingItems,collectAsLazyPagingItems,itemKey,itemContentTypein UI, retry/refresh →LoadStatereferences/paging.md - , offline-first paging, network + cache paging,
RemoteMediator→loadState.source.refreshreferences/paging-offline.md - Paging with MVI, dual-flow pattern, paging tests (,
asSnapshot),TestPager, paging anti-patterns →CombinedLoadStatesreferences/paging-mvi-testing.md
- 、
PagingSource、PagingData配置、Pager、PagingConfig、失效机制 →pagingDataFlowreferences/paging.md - 、
LazyPagingItems、collectAsLazyPagingItems、itemKey、UI层itemContentType、重试/刷新 →LoadStatereferences/paging.md - 、离线优先分页、网络+缓存分页、
RemoteMediator→loadState.source.refreshreferences/paging-offline.md - MVI架构下的分页、双流模式、分页测试(、
asSnapshot)、TestPager、分页反模式 →CombinedLoadStatesreferences/paging-mvi-testing.md
Theming and design systems
主题与设计系统
- ,
MaterialTheme,ColorScheme,Typography, dynamic color, M3 tokens, color roles →Shapesreferences/theming-material3.md - Material 3 Expressive, ,
MaterialExpressiveTheme,ButtonGroup,SplitButton,FloatingActionButtonMenu(wavy),LoadingIndicator,HorizontalFloatingToolbar→@ExperimentalMaterial3ExpressiveApi(motion:references/theming-material3.md)references/material3-motion.md - Atom, molecule, organism, template, component hierarchy, design system structure, reusable components, design tokens →
references/atomic-design.md - Figma → Compose, screenshot → composable, design token translation, spec-to-code, redline interpretation →
references/design-to-compose.md - ,
Style {},MutableStyleState(experimental Foundation Styles API) →Modifier.styleable()references/styles-experimental.md
- 、
MaterialTheme、ColorScheme、Typography、动态颜色、M3令牌、颜色角色 →Shapesreferences/theming-material3.md - Material 3 Expressive、、
MaterialExpressiveTheme、ButtonGroup、SplitButton、波浪式FloatingActionButtonMenu、LoadingIndicator、HorizontalFloatingToolbar→@ExperimentalMaterial3ExpressiveApi(动效部分参考:references/theming-material3.md)references/material3-motion.md - 原子、分子、有机体、模板、组件层级、设计系统结构、可复用组件、设计令牌 →
references/atomic-design.md - Figma → Compose、截图转可组合函数、设计令牌转换、设计稿转代码、标注解读 →
references/design-to-compose.md - 、
Style {}、MutableStyleState(实验性Foundation Styles API) →Modifier.styleable()references/styles-experimental.md
Multiplatform and platform-specific
多平台与平台特定功能
- iOS/Desktop/Web CMP targets, /
expect,actual,commonMain,Res.drawable, platform-specific composables →Res.stringreferences/multiplatform.md - (iOS),
ComposeUIViewController/Window/Tray(Desktop),MenuBar,UIKitView(Web), platform interop →ComposeViewportreferences/platform-specifics.md - TV Compose, , D-pad focus,
androidx.tvon TV,FocusRequester,Carousel(TV), 10-foot UI, leanback migration →NavigationDrawerreferences/tv-compose.md
- iOS/桌面/Web端CMP目标、/
expect、actual、commonMain、Res.drawable、平台特定可组合函数 →Res.stringreferences/multiplatform.md - (iOS)、
ComposeUIViewController/Window/Tray(桌面端)、MenuBar、UIKitView(Web端)、平台互操作 →ComposeViewportreferences/platform-specifics.md - TV Compose、、D-pad焦点、TV端
androidx.tv、FocusRequester、TV版Carousel、10英尺UI、Leanback迁移 →NavigationDrawerreferences/tv-compose.md
Interop and accessibility
互操作与无障碍
- Compose inside XML, ,
AndroidView,ComposeView, hybrid migration, View → Compose interop →AbstractComposeViewreferences/view-composition.md - Accessibility, , TalkBack, touch target size,
Modifier.semantics, WCAG, traversal order →contentDescriptionreferences/accessibility.md
- XML中嵌入Compose、、
AndroidView、ComposeView、混合迁移、View → Compose互操作 →AbstractComposeViewreferences/view-composition.md - 无障碍、、TalkBack、触摸目标尺寸、
Modifier.semantics、WCAG、遍历顺序 →contentDescriptionreferences/accessibility.md
Production, review, migration
生产环境、审查与迁移
- Production crash, ANR, Compose stack trace, leak, zero-size DrawScope, duplicate keys, stale
remember→derivedStateOfreferences/production-crash-playbook.md - PR review, code review, "review this diff", composable anti-patterns, smell detection, GitHub PR URL →
references/pr-review.md - Deprecated Compose API, "removed in version X", migration from old API, replaced symbols →
references/deprecated-patterns.md - Experimental opt-in, ,
@OptIn, unstable API usage →@ExperimentalFoundationStyleApi(for Styles); for general guidance, the relevant topic filereferences/styles-experimental.md - Session start, project detection, auto-init →
references/auto-init.md
- 生产环境崩溃、ANR、Compose堆栈跟踪、泄漏、零尺寸DrawScope、重复键、过期的
remember→derivedStateOfreferences/production-crash-playbook.md - PR审查、代码审查、“审查此diff”、可组合函数反模式、坏味道检测、GitHub PR链接 →
references/pr-review.md - 已废弃的Compose API、“在版本X中移除”、旧API迁移、替换符号 →
references/deprecated-patterns.md - 实验性API opt-in、、
@OptIn、不稳定API使用 →@ExperimentalFoundationStyleApi(Styles相关);通用指导请查看对应主题文件references/styles-experimental.md - 会话开始、项目检测、自动初始化 →
references/auto-init.md
Source-code receipts (cite, don't route to)
源码凭证(仅用于引用,不作为路由依据)
- "Show me the actual implementation", "where in androidx is this", internal Compose mechanics → load the topic reference first, then cite the matching file:
references/source-code/*.md- Runtime/state internals (Composer, Snapshot, Effects, Remember) →
references/source-code/runtime-source.md - UI/layout/measurement/draw internals →
references/source-code/ui-source.md - Foundation (LazyList, Pager, Clickable, Scrollable, BasicTextField) →
references/source-code/foundation-source.md - Material3 components →
references/source-code/material3-source.md - Navigation Compose internals →
references/source-code/navigation-source.md - CMP entry points (Window, ComposeUIViewController, UIKitView, ComposeViewport) →
references/source-code/cmp-source.md
- Runtime/state internals (Composer, Snapshot, Effects, Remember) →
- “给我看实际实现”、“这个在androidx的什么位置”、Compose内部机制 → 先加载对应主题的参考文件,再引用匹配的文件:
references/source-code/*.md- 运行时/状态内部机制(Composer、Snapshot、Effects、Remember)→
references/source-code/runtime-source.md - UI/布局/测量/绘制内部机制 →
references/source-code/ui-source.md - Foundation(LazyList、Pager、Clickable、Scrollable、BasicTextField)→
references/source-code/foundation-source.md - Material3组件 →
references/source-code/material3-source.md - Navigation Compose内部机制 →
references/source-code/navigation-source.md - CMP入口点(Window、ComposeUIViewController、UIKitView、ComposeViewport)→
references/source-code/cmp-source.md
- 运行时/状态内部机制(Composer、Snapshot、Effects、Remember)→
Compose Expert Skill
Compose专家技能
Non-opinionated, practical guidance for writing correct, performant Compose code —
across Android, Desktop, iOS, and Web. Covers Jetpack Compose and Compose Multiplatform.
Backed by analysis of actual source code from and
.
androidx/androidxJetBrains/compose-multiplatform-core为编写正确、高性能的Compose代码提供中立、实用的指导——覆盖Android、桌面端、iOS和Web端。涵盖Jetpack Compose与Compose Multiplatform。基于对和真实源码的分析构建。
androidx/androidxJetBrains/compose-multiplatform-coreReview Mode
审查模式
Activate when the input contains a GitHub PR URL () or
explicit review phrases: "review this PR", "review this diff", "check this code",
"what's wrong with this".
github.com/.+/pull/\d+When Review Mode activates:
- Do not follow the generation workflow below
- Read and follow its workflow exclusively
references/pr-review.md - Output a structured local review report — do not post to GitHub
触发条件:输入内容包含GitHub PR链接()或明确的审查短语:“review this PR”、“review this diff”、“check this code”、“what's wrong with this”。
github.com/.+/pull/\d+审查模式激活后:
- 不要遵循下方的生成工作流
- 阅读并严格遵循其中的工作流
references/pr-review.md - 输出结构化的本地审查报告——不要发布到GitHub
Workflow
工作流
When helping with Compose code, follow this checklist:
在协助处理Compose代码时,请遵循以下检查清单:
1. Understand the request
1. 理解需求
- What Compose layer is involved? (Runtime, UI, Foundation, Material3, Navigation)
- Is this a state problem, layout problem, performance problem, or architecture question?
- Is this Android-only or Compose Multiplatform (CMP)?
- 涉及Compose的哪一层?(Runtime、UI、Foundation、Material3、Navigation)
- 这是状态问题、布局问题、性能问题,还是架构问题?
- 是仅Android端的问题,还是Compose Multiplatform(CMP)的问题?
2. Analyze the design (if visual reference provided)
2. 分析设计(如果提供了视觉参考)
- If the user shares a Figma frame, screenshot, or design spec, consult
references/design-to-compose.md - Decompose the design into a composable tree using the 5-step methodology
- Map design tokens to MaterialTheme, spacing to CompositionLocals
- Identify animation needs and consult for recipes
references/animation.md
- 如果用户分享了Figma画板、截图或设计规范,请参考
references/design-to-compose.md - 使用5步方法论将设计拆解为可组合函数树
- 将设计令牌映射到MaterialTheme,间距映射到CompositionLocals
- 确定动画需求,并参考中的实现方案
references/animation.md
3. Consult the right reference
3. 查阅正确的参考资料
Read the relevant reference file(s) from before answering:
references/| Topic | Reference File |
|---|---|
| |
| Structuring composables, slots, extraction, preview | |
Modifier ordering, custom modifiers, | |
| |
| |
| |
| |
| |
| |
| Recomposition skipping, stability, baseline profiles, benchmarking | |
| Semantics, content descriptions, traversal order, testing | |
| Removed/replaced APIs, migration paths from older Compose versions | |
Styles API (experimental): | |
| Figma/screenshot decomposition, design tokens, spacing, modifier ordering | |
| Production crash patterns, defensive coding, state/performance rules | |
Compose Multiplatform, | |
| Desktop (Window, Tray, MenuBar), iOS (UIKitView), Web (ComposeViewport) | |
| TV Compose: Surface, Carousel, NavigationDrawer, Cards, focus, D-pad | |
M3 motion tokens, | |
| PR URL, code review, "review this PR", "what's wrong with this" | |
| Session start, project detection | |
| Atomic design, design system, reusable component, component library, design tokens | |
回答前请先阅读目录下的相关参考文件:
references/| 主题 | 参考文件 |
|---|---|
| |
| 可组合函数结构设计、插槽、提取、预览 | |
Modifier顺序、自定义修饰符、 | |
| |
| |
| |
| |
| |
| |
| 重组跳过、稳定性、基准配置文件、性能基准测试 | |
| 语义、内容描述、遍历顺序、测试 | |
| 已移除/替换的API、旧版Compose的迁移路径 | |
Styles API(实验性): | |
| Figma/截图拆解、设计令牌、间距、modifier顺序 | |
| 生产环境崩溃模式、防御性编程、状态/性能规则 | |
Compose Multiplatform、 | |
| 桌面端(Window、Tray、MenuBar)、iOS(UIKitView)、Web端(ComposeViewport) | |
| TV Compose:Surface、Carousel、NavigationDrawer、Cards、焦点、D-pad | |
M3动效令牌、 | |
| PR链接、代码审查、“review this PR”、“what's wrong with this” | |
| 会话开始、项目检测 | |
| 原子设计、设计系统、可复用组件、组件库、设计令牌 | |
4. Apply and verify
4. 应用并验证
- Write code that follows the patterns in the reference
- Flag any anti-patterns you see in the user's existing code
- Suggest the minimal correct solution — don't over-engineer
- 编写遵循参考资料中模式的代码
- 指出用户现有代码中存在的反模式
- 建议最小可行的正确解决方案——不要过度设计
4a. Component building mode
4a. 组件构建模式
When the request involves building a component (composable that renders UI):
- Consult
references/atomic-design.md - Classify the component level (atom, molecule, organism, template)
- Apply the "Ask" prompt from Section 5 before scaffolding code
- Ensure the component satisfies the atom contract (modifier, slots, tokens, defaults)
当需求涉及构建组件(渲染UI的可组合函数)时:
- 参考
references/atomic-design.md - 对组件进行层级分类(原子、分子、有机体、模板)
- 在搭建代码框架前,应用第5节中的“提问”提示
- 确保组件满足原子契约(modifier、插槽、令牌、默认值)
5. Cite the source
5. 引用来源
When referencing Compose internals, point to the exact source file:
// See: compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/Composer.kt引用Compose内部实现时,请指明具体的源文件:
// See: compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/Composer.ktKey Principles
核心原则
-
Compose thinks in three phases: Composition → Layout → Drawing. State reads in each phase only trigger work for that phase and later ones.
-
Recomposition is frequent and cheap — but only if you help the compiler skip unchanged scopes. Use stable types, avoid allocations in composable bodies.
-
Modifier order matters.is visually different from
Modifier.padding(16.dp).background(Color.Red).Modifier.background(Color.Red).padding(16.dp) -
State should live as low as possible and be hoisted only as high as needed. Don't put everything in a ViewModel just because you can.
-
Side effects exist to bridge Compose's declarative world with imperative APIs. Use the right one for the job — misusing them causes bugs that are hard to trace.
-
Compose Multiplatform shares the runtime but not the platform. UI code inis portable. Platform-specific APIs (
commonMain,LocalContext,BackHandler) requireWindow/expector conditional source sets.actual
-
Compose的工作分为三个阶段:组合(Composition)→ 布局(Layout)→ 绘制(Drawing)。每个阶段中的状态读取只会触发该阶段及后续阶段的工作。
-
重组(Recomposition)频繁且低成本——但前提是你要帮助编译器跳过未变化的作用域。使用稳定类型,避免在可组合函数体内分配对象。
-
Modifier的顺序很重要。的视觉效果与
Modifier.padding(16.dp).background(Color.Red)不同。Modifier.background(Color.Red).padding(16.dp) -
状态应尽可能放在低层,仅在需要时才向上提升。不要为了方便就把所有东西都放在ViewModel里。
-
副作用(Side effects)的存在是为了衔接Compose的声明式世界与命令式API。要为场景选择合适的副作用——误用会导致难以排查的bug。
-
Compose Multiplatform共享运行时,但不共享平台实现。中的UI代码是可移植的。平台特定的API(
commonMain、LocalContext、BackHandler)需要使用Window/expect或条件源集。actual
Source Code Receipts
源码凭证
Beyond the guidance docs, this skill bundles the actual source code from
(branch: ) and
(branch: ). When you need to verify how something works internally, or the
user asks "show me the actual implementation", read the raw source from
:
androidx/androidxandroidx-mainJetBrains/compose-multiplatform-corejb-mainreferences/source-code/| Module | Source Reference | Key Files Inside |
|---|---|---|
| Runtime | | Composer.kt, Recomposer.kt, State.kt, Effects.kt, CompositionLocal.kt, Remember.kt, SlotTable.kt, Snapshot.kt |
| UI | | AndroidCompositionLocals.android.kt, Modifier.kt, Layout.kt, LayoutNode.kt, ModifierNodeElement.kt, DrawModifier.kt |
| Foundation | | LazyList.kt, LazyGrid.kt, BasicTextField.kt, Clickable.kt, Scrollable.kt, Pager.kt |
| Material3 | | MaterialTheme.kt, ColorScheme.kt, Button.kt, Scaffold.kt, TextField.kt, NavigationBar.kt |
| Navigation | | NavHost.kt, ComposeNavigator.kt, NavGraphBuilder.kt, DialogNavigator.kt |
| CMP | | Window.kt, ComposeUIViewController.kt, UIKitView.kt, ComposeViewport.kt, ResourceReader.kt |
除了指导文档外,本技能还打包了来自(分支:)和(分支:)的真实源码。当你需要验证内部实现逻辑,或用户要求“给我看实际实现”时,请从目录读取源码:
androidx/androidxandroidx-mainJetBrains/compose-multiplatform-corejb-mainreferences/source-code/| 模块 | 源码参考文件 | 包含的关键文件 |
|---|---|---|
| Runtime | | Composer.kt、Recomposer.kt、State.kt、Effects.kt、CompositionLocal.kt、Remember.kt、SlotTable.kt、Snapshot.kt |
| UI | | AndroidCompositionLocals.android.kt、Modifier.kt、Layout.kt、LayoutNode.kt、ModifierNodeElement.kt、DrawModifier.kt |
| Foundation | | LazyList.kt、LazyGrid.kt、BasicTextField.kt、Clickable.kt、Scrollable.kt、Pager.kt |
| Material3 | | MaterialTheme.kt、ColorScheme.kt、Button.kt、Scaffold.kt、TextField.kt、NavigationBar.kt |
| Navigation | | NavHost.kt、ComposeNavigator.kt、NavGraphBuilder.kt、DialogNavigator.kt |
| CMP | | Window.kt、ComposeUIViewController.kt、UIKitView.kt、ComposeViewport.kt、ResourceReader.kt |
Two-layer approach
两层使用方法
- Start with guidance — read the topic-specific reference (e.g., )
references/state-management.md - Go deeper with source — if the user wants receipts or you need to verify, read from
references/source-code/
- 从指导文档开始——先阅读对应主题的参考文件(例如)
references/state-management.md - 用源码深入验证——如果用户需要凭证或你需要确认实现时,再阅读中的源码
references/source-code/
Source tree map
源码树结构
androidx/androidx (branch: androidx-main)
├── compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/
├── compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/
├── compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/
├── compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/
├── compose/material3/material3/src/commonMain/kotlin/androidx/compose/material3/
├── compose/navigation/navigation-compose/src/commonMain/kotlin/androidx/navigation/compose/
├── tv/tv-material/src/main/java/androidx/tv/material3/
└── tv/tv-foundation/src/main/java/androidx/tv/foundation/
compose-multiplatform-core (branch: jb-main)
├── compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/window/
├── compose/ui/ui/src/iosMain/kotlin/androidx/compose/ui/window/
├── compose/ui/ui/src/webMain/kotlin/androidx/compose/ui/window/
├── compose/ui/ui/src/skikoMain/kotlin/androidx/compose/ui/
└── compose/foundation/foundation/src/skikoMain/kotlin/androidx/compose/foundation/
compose-multiplatform (resources library)
└── components/resources/library/src/commonMain/androidx/androidx (branch: androidx-main)
├── compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/
├── compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/
├── compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/
├── compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/
├── compose/material3/material3/src/commonMain/kotlin/androidx/compose/material3/
├── compose/navigation/navigation-compose/src/commonMain/kotlin/androidx/navigation/compose/
├── tv/tv-material/src/main/java/androidx/tv/material3/
└── tv/tv-foundation/src/main/java/androidx/tv/foundation/
compose-multiplatform-core (branch: jb-main)
├── compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/window/
├── compose/ui/ui/src/iosMain/kotlin/androidx/compose/ui/window/
├── compose/ui/ui/src/webMain/kotlin/androidx/compose/ui/window/
├── compose/ui/ui/src/skikoMain/kotlin/androidx/compose/ui/
└── compose/foundation/foundation/src/skikoMain/kotlin/androidx/compose/foundation/
compose-multiplatform (resources library)
└── components/resources/library/src/commonMain/