跳至正文
OpenAgentSkill
浏览已开放 · 目录记录日期 2026-11-21 · 自动更新和账户服务暂时关闭。
设计与 UI

android-kotlin-compose

Jetpack Compose UI engineering for 2026 — edge-to-edge, Material 3, recomposition stability, Modifier ordering, LazyColumn performance, and animations. Use when building composables, fixing jank, theming, adaptive layouts, Canvas drawing, auditing screens, or asking "why does my screen recompose", "Modifier order", "edge to edge Compose", "audit this composable", "review this screen".

haidrrrry · 已有静态检查记录

安装与使用

运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。

npx skills add haidrrrry/compose-kotlin-agent-skills --skill android-kotlin-compose

技能说明


name: android-kotlin-compose description: > Jetpack Compose UI engineering for 2026 — edge-to-edge, Material 3, recomposition stability, Modifier ordering, LazyColumn performance, and animations. Use when building composables, fixing jank, theming, adaptive layouts, Canvas drawing, auditing screens, or asking "why does my screen recompose", "Modifier order", "edge to edge Compose", "audit this composable", "review this screen".

Android Kotlin — Compose UI Module

Parent kit: ../../SKILL.md · Index: ../../AGENTS.md · Banned list: ../../references/00-banned-antipatterns.md

REVIEW MODE

Trigger phrases: "audit this file", "check this composable", "review this screen", "review mode", "a11y pass on this composable".

When triggered, silently run this 6-point checklist on the target file before responding. Cite failures by checklist number and banned-antipattern row from ../../references/00-banned-antipatterns.md.

#CheckFail if
1Modifier paramMissing modifier: Modifier = Modifier or not last optional param
2State hoistingScreen/business state inside @Composable that belongs in ViewModel
3Lazy list keysLazyColumn/LazyRow items missing key = {} or contentType = {}
4Lifecycle collectionUses collectAsState() instead of collectAsStateWithLifecycle()
5Side effects in compositionIO, DB, network, or viewModelScope work directly in composable body
6StabilityData class params to child composables lack @Stable or @Immutable

Output format for REVIEW MODE:

## Compose audit — <filename>

| # | Status | Finding |
|---|--------|---------|
| 1 | PASS/FAIL | ... |
...

### Banned antipatterns hit
- Row N: <pattern> → <fix>

### Suggested diff
<code block with minimal fix>

Load ../../references/17-accessibility.md when audit includes TalkBack, touch targets, or contrast.


AUTHORING MODE

Default behavior when writing new Compose UI (not auditing). Follow all rules below.

Read First

FileWhen
../../references/02-compose-ui.mdStability, slots, Material 3, CompositionLocal themes
../../references/03-animations.mdSprings, Canvas, gestures
../../references/10-performance.mdderivedStateOf, LazyColumn keys, baseline profiles
../../references/16-coil-image.mdAsyncImage, Coil 3.4 network dep
../../references/17-accessibility.mdSemantics, 48dp targets, WCAG

Edge-to-Edge (Default — AGP 9 / API 35+)

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        enableEdgeToEdge()
        super.onCreate(savedInstanceState)
        setContent {
            AppTheme {
                Scaffold(
                    modifier = Modifier.fillMaxSize(),
                    contentWindowInsets = WindowInsets(0, 0, 0, 0)
                ) { innerPadding ->
                    NavHost(
                        modifier = Modifier
                            .fillMaxSize()
                            .padding(innerPadding)
                    )
                }
            }
        }
    }
}
  • enableEdgeToEdge() on every ComponentActivity
  • Respect WindowInsets — never hardcode status bar padding
  • Use WindowInsets.safeDrawing for interactive content
  • Test gesture nav bar + display cutout on physical device

Composable Contract

@Composable
fun AccountCard(
    account: AccountUi,
    onClick: () -> Unit,
    modifier: Modifier = Modifier  // always first param after required data
) {
    Card(
        modifier = modifier
            .fillMaxWidth()
            .clip(RoundedCornerShape(12.dp))
            .clickable(onClick = onClick)
    ) {
        Text(
            text = stringResource(R.string.account_title, account.name),
            style = MaterialTheme.typography.titleMedium
        )
    }
}

Recomposition Rules

  1. Extract sub-composables for separate restart scopes
  2. Defer scroll/animation reads: Modifier.offset { IntOffset(...) }
  3. @Immutable on UiState / list wrappers passed to children
  4. remember(keys) { derivedStateOf { } } for expensive derived values
  5. Never write state in composable body after read (backwards write)

LazyColumn Checklist

  • key = { it.id } on every items()
  • contentType when row layouts differ
  • Stable lambdas: remember(id) { { onClick(id) } }
  • No nested verticalScroll + LazyColumn
  • Sort/filter in ViewModel or remember, not inline in items {}

Anti-Patterns (Compose)

BannedFix
Hardcoded Text("Save")stringResource(R.string.action_save)
collectAsState() on AndroidcollectAsStateWithLifecycle()
Modifier.clickable before padding when touch target should exclude marginOrder: padding → clip → background → clickable
items(list) without keyitems(list, key = { it.id })
Raw fontSize = 16.spMaterialTheme.typography.bodyLarge

Full list: ../../references/00-banned-antipatterns.md