compose-ui by new-silvermoon/awesome-android-agent-skills
npx skills add https://github.com/new-silvermoon/awesome-android-agent-skills --skill compose-ui遵循以下指南来创建高性能、可复用且可测试的 Composable 组件。
尽可能通过将状态移至调用者来使 Composable 组件无状态化。
模式:函数签名通常应如下所示:
@Composable
fun MyComponent( value: String, // 状态向下流动 onValueChange: (String) -> Unit, // 事件向上流动 modifier: Modifier = Modifier // 标准修饰符参数 )
优点:将 UI 与简单的状态存储解耦,使其更易于预览和测试。
ViewModel 集成:屏幕级别的 Composable 从 ViewModel 获取状态(viewModel.uiState.collectAsStateWithLifecycle())并将其向下传递。
modifier: Modifier = Modifier 作为第一个可选参数。modifier 应用于你的 Composable 的布局元素。广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
padding().clickable() 与 clickable().padding() 是不同的。通常,如果你希望内边距区域也可点击,请在点击监听器之后应用影响布局的修饰符(如 padding)。remember:使用 remember { ... } 在重组之间缓存昂贵的计算。
derivedStateOf:当某个状态频繁变化(如滚动位置)但 UI 只需要对阈值或摘要做出反应时(例如,显示“跳转到顶部”按钮),使用 derivedStateOf { ... }。这可以防止不必要的重组。
val showButton by remember {
derivedStateOf { listState.firstVisibleItemIndex > 0 }
}
Lambda 稳定性:优先使用方法引用(例如 viewModel::onEvent)或已记忆的 lambda,以防止不稳定类型触发子组件的重组。
MaterialTheme.colorScheme 和 MaterialTheme.typography,而不是硬编码的颜色或文本样式。DesignSystem.kt 或 Components.kt)。@Preview(showBackground = true),并在适用时包含浅色/深色模式预览。每周安装量
212
代码仓库
GitHub 星标数
552
首次出现
2026年1月27日
安全审计
安装于
opencode187
codex185
gemini-cli173
github-copilot164
kimi-cli151
amp150
Follow these guidelines to create performant, reusable, and testable Composables.
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.
modifier: Modifier = Modifier as the first optional parameter.modifier to the root layout element of your Composable.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.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.
MaterialTheme.colorScheme and MaterialTheme.typography instead of hardcoded colors or text styles.DesignSystem.kt or Components.kt) if they are shared across features.@Preview(showBackground = true) and include Light/Dark mode previews if applicable.Weekly Installs
212
Repository
GitHub Stars
552
First Seen
Jan 27, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode187
codex185
gemini-cli173
github-copilot164
kimi-cli151
amp150
Kotlin 协程与 Flow 实战指南:结构化并发、响应式流与测试
968 周安装