SKILL

compose-multiplatform-patterns

Compose Multiplatform and Jetpack Compose patterns in KMP projects — state management, navigation, theming, performance optimization, and platform-specific UI.

Machine translation
Read the original Chinese text

KMP项目中的Compose Multiplatform和Jetpack Compose模式——状态管理、导航、主题化、性能优化和平台特定UI。

Target: Target not categorized. Automatically collected · unverified.

Excerpt from the author’s documentation

Extracted from a fixed version of SKILL.md in its original language. This is the author’s documentation; installation, compatibility and runtime results have not been verified by this site.

Read the original Chinese text

Topics in the source

  • Compose 多平台模式
  • 何时启用
  • 状态管理
  • ViewModel + 单一状态对象
  • 在 Compose 中收集状态
  • 事件接收器模式
  • 导航
  • 类型安全导航(Compose Navigation 2.8+)

使用 Compose Multiplatform 和 Jetpack Compose 构建跨 Android、iOS、桌面和 Web 的共享 UI 的模式。涵盖状态管理、导航、主题和性能。 构建 Compose UI(Jetpack Compose 或 Compose Multiplatform) 使用 ViewModel 和 Compose 状态管理 UI 状态 在 KMP 或 Android 项目中实现导航 设计可复用的可组合项和设计系统 优化重组和渲染性能 使用单个数据类表示屏幕状态。将其暴露为 StateFlow 并在 Compose 中收集: 对于复杂屏幕,使用密封接口表示事件,而非多个回调 lambda: 将路由定义为 @Serializable 对象: 使用 dialog() 和覆盖层模式,而非命令式的显示/隐藏: 使用槽位参数设计可组合项以获得灵活性: 修饰符顺序很重要 —— 按此顺序应用: 当所有属性都稳定时,将类标记为 @Stable 或 @Immutable: 在 ViewModel 中使用 mutableStateOf,而 MutableStateFlow 配合 collectAsStateWithLifecycle 对生命周期更安全 将 NavController 深入传递到可组合项中 —— 应传递 lambda 回调 在 @Composable 函数中进行繁重计算 —— 应移至 ViewModel 或 remember {} 使用 LaunchedEffect(Unit) 作为 ViewModel 初始化的替代 —— 在某些设置中,它会在配置更改时重新运行 在可组合项参数中创建新的对象实例 —— 会导致不必要的重组 查看技能:android-clean-architecture 了解模块结构和分层。 查看技能:kotlin-coroutines-flows 了解协程和 Flow 模式。

Source repository
affaan-m/ECC
Source file
docs/zh-CN/skills/compose-multiplatform-patterns/SKILL.md
Fixed revision
d2ef2680594f9a17526a6e1a2e18b3d242c5d17b
Read the complete original documentation ↗

Sources and evidence

This record was collected automatically. Its documentation, suitability and runtime behavior have not been manually verified.

Author: affaan-m/ECC · original repository metadata. Documentation review: Not reviewed. Last source check: 2026-11-09T14:01:50.221Z.

Categories are inferred from names, descriptions and paths. They do not establish compatibility.

License and attribution

MIT. Third-party content and copyright remain with their authors. Refer to the original license and terms.

Original license ↗

Synchronization, copying and user-reported success do not mark a resource as runtime-tested.

Limitations and notes

  • Collecting metadata does not mean this site has installed, adapted, runtime-tested or security-reviewed the resource.