Agent Skillsmaxrave-dev/SimpMusic › compose-ui

compose-ui

GitHub

提供Jetpack Compose构建UI的最佳实践,涵盖状态提升、性能优化及主题设置。指导编写或重构可组合函数,确保UI组件具备高性能、可复用性和可测试性。

.claude/skills/compose-ui/SKILL.md maxrave-dev/SimpMusic

触发场景

编写新的Jetpack Composable函数 重构现有Compose UI代码以优化性能或结构

安装

npx skills add maxrave-dev/SimpMusic --skill compose-ui -g -y
更多选项

非标准路径

npx skills add https://github.com/maxrave-dev/SimpMusic/tree/dev/.claude/skills/compose-ui -g -y

不安装直接使用

npx skills use maxrave-dev/SimpMusic@compose-ui

指定 Agent (Claude Code)

npx skills add maxrave-dev/SimpMusic --skill compose-ui -a claude-code -g -y

安装 repo 全部 skill

npx skills add maxrave-dev/SimpMusic --all -g -y

预览 repo 内 skill

npx skills add maxrave-dev/SimpMusic --list

SKILL.md

Frontmatter
{
    "name": "compose-ui",
    "description": "Best practices for building UI with Jetpack Compose, focusing on state hoisting, detailed performance optimizations, and theming. Use this when writing or refactoring Composable functions."
}

Jetpack Compose Best Practices

Instructions

Follow these guidelines to create performant, reusable, and testable Composables.

1. State Hoisting (Unidirectional Data Flow)

Make Composables stateless whenever possible by moving state to the caller.

  • Pattern: Function signature should usually look like:
    @Composable
    fun MyComponent(
        value: String,              // State flows down
        onValueChange: (String) -> Unit, // Events flow up
        modifier: Modifier = Modifier // Standard modifier parameter
    )
    
  • Benefit: Decouples the UI from simple state storage, making it easier to preview and test.
  • ViewModel Integration: The screen-level Composable retrieves state from the ViewModel (viewModel.uiState.collectAsStateWithLifecycle()) and passes it down.

2. Modifiers

  • Default Parameter: Always provide a modifier: Modifier = Modifier as the first optional parameter.
  • Application: Apply this modifier to the root layout element of your Composable.
  • Ordering matters: padding().clickable() is different from clickable().padding(). Generally apply layout-affecting modifiers (like padding) after click listeners if you want the padding to be clickable.

3. Performance Optimization

  • remember: Use remember { ... } to cache expensive calculations across recompositions.
  • derivedStateOf: Use derivedStateOf { ... } when a state changes frequently (like scroll position) but the UI only needs to react to a threshold or summary (e.g., show "Jump to Top" button). This prevents unnecessary recompositions.
    val showButton by remember {
        derivedStateOf { listState.firstVisibleItemIndex > 0 }
    }
    
  • Lambda Stability: Prefer method references (e.g., viewModel::onEvent) or remembered lambdas to prevent unstable types from triggering recomposition of children.

4. Theming and Resources

  • Use MaterialTheme.colorScheme and MaterialTheme.typography instead of hardcoded colors or text styles.
  • Organize simple UI components into specific files (e.g., DesignSystem.kt or Components.kt) if they are shared across features.

5. Previews

  • Create a private preview function for every public Composable.
  • Use @Preview(showBackground = true) and include Light/Dark mode previews if applicable.
  • Pass dummy data (static) to the stateless Composable for the preview.

版本历史

  • 11f5926 当前 2026-07-30 20:16

同 Skill 集合

.claude/skills/android-accessibility/SKILL.md
.claude/skills/android-architecture/SKILL.md
.claude/skills/android-coroutines/SKILL.md
.claude/skills/android-data-layer/SKILL.md
.claude/skills/android-emulator-skill/SKILL.md
.claude/skills/android-gradle-logic/SKILL.md
.claude/skills/android-retrofit/SKILL.md
.claude/skills/android-testing/SKILL.md
.claude/skills/android-viewmodel/SKILL.md
.claude/skills/coil-compose/SKILL.md
.claude/skills/compose-navigation/SKILL.md
.claude/skills/compose-performance-audit/SKILL.md
.claude/skills/gradle-build-performance/SKILL.md
.claude/skills/jetpack-compose/SKILL.md
.claude/skills/kotlin-concurrency-expert/SKILL.md
.claude/skills/marketing-ideas/SKILL.md
.claude/skills/mobile-android-design/SKILL.md
.claude/skills/simpmusic-icons/SKILL.md
.claude/skills/xml-to-compose-migration/SKILL.md
.claude/skills/find-skills/SKILL.md
.claude/skills/kmp/SKILL.md
.claude/skills/ui-ux-pro-max/SKILL.md

元信息

文件数
0
版本
b694e28
Hash
e1d56573
收录时间
2026-07-30 20:16

首页 - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-09 08:42
浙ICP备14020137号-1 $访客地图$