CocktailRecipes / ui-rules
Cursor rule1 starsChanged 20 months agoMITView on GitHub
UI Guideline: Jetpack Compose coding standards & component conventions
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 4,373 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository19 other files it gives its agents.
- .cursor/rules/android-kotlin-compose-rules/break_down_rule.mdcCursor rule
- .cursor/rules/android-kotlin-compose-rules/implementation_rule.mdcCursor rule
- .cursor/rules/android-kotlin-compose-rules/project_overview_template.mdcCursor rule
- .cursor/rules/android-kotlin-compose-rules/technical_design_documentation_rule.mdcCursor rule
- .cursor/rules/core-rules/readme.mdCursor rule
- .cursor/rules/core-rules/rule-generating-agent.mdcCursor rule
- .cursor/rules/core-rules/rule-update-cursor-modes-manual.mdcCursor rule
- .cursor/rules/core-rules/workflow-agile-manual.mdcCursor rule
- .cursor/rules/global-rules/emoji-communication-always.mdcCursor rule
- .cursor/rules/global-rules/readme.mdCursor rule
- .cursor/rules/isolation_rules/main.mdcCursor rule
- .cursor/rules/tool-rules/git-commit-push-agent.mdcCursor rule
- .cursor/rules/tool-rules/readme.mdCursor rule
- .cursor/rules/ui-rules/readme.mdCursor rule
- .cursor/rules/workflows/arch.mdcCursor rule
- .cursor/rules/workflows/dev.mdcCursor rule
- .cursor/rules/workflows/pm.mdcCursor rule
- .cursor/rules/workflows/task-breakdown-always.mdcCursor rule
- .cursor/rules/workflows/workflow-agile-manual.mdcCursor rule
The file
We split this compose_ui_guideline.mdc into the rules it gives an agent
12 rules. About 0 are common, 2 are distinctive, and 10 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
10
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 16
Section/Container: use suffix Section or Container for layout-only groupings.
- Distinctive: line 17
Callback parameters: should always be placed last (per Kotlin coding style).
- Very specific: line 31
modifier: should come first after data-state params to enable readable chaining. - Distinctive: line 32
Avoid nullable parameters that mean “off” – provide meaningful default values instead.
- Very specific: line 38
Use rememberSaveable for states that need to survive configuration changes.
- Very specific: line 51
Always assign contentDescription to images.
- Very specific: line 52
Use semantics {} to override roles when needed.
- Very specific: line 53
Use mergeDescendants = true to combine children if too verbose for screen readers.
- Very specific: line 57
Every public composable must have at least one @Preview in the same file with default theme.
- Very specific: line 58
Use MaterialTheme.colorScheme and MaterialTheme.typography for design tokens.
- Very specific: line 59
Avoid hard-coded dp/sp values – prefer dimensionResource for design specs.
- Very specific: line 64
Default values should reflect design specs (e.g., elevation = ButtonDefaults.elevatedButtonElevation()).
≈ “Common” is an estimate: at least 1 in 5 of the 7,324 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
---
description: UI Guideline: Jetpack Compose coding standards & component conventions
globs: app/src/main/java/com/nguyenmoclam/cocktailrecipes/ui/**/*.kt
alwaysApply: false
---
# Compose UI Guideline– Android Kotlin Jetpack Compose
## 1. Naming Conventions
- **Stateless vs Stateful**
- **Stateless**: `@Composable fun ItemCard(item: Item, onClick: () -> Unit)` – displays the passed-in data without holding state.
- **Stateful**: append `WithState()` or define inside a `Defaults` class (based on API guideline).
- **Screens**: end with **`Screen`** (e.g., `HomeScreen`, `DetailScreen`).
- **Section/Container**: use suffix **`Section`** or **`Container`** for layout-only groupings.
- **Callback parameters** should always be placed last (per Kotlin coding style).
## 2. Function Signature
```kotlin
@Composable
fun FancyButton(
text: String,
modifier: Modifier = Modifier,
enabled: Boolean = true,
onClick: () -> Unit,
)
```
- **`modifier`** should come first after data-state params to enable readable chaining.
- Avoid nullable parameters that mean “off” – provide meaningful default values instead.
## 3. Stable State & Recomposition
- Composables must be **idempotent** – same input produces same UI.
- Inputs should be **immutable** or marked with `@Stable`. If passing `MutableState`, wrap with `remember { mutableStateOf(...) }`.
- Use `rememberSaveable` for states that need to survive configuration changes.
## 4. Modifier Order
1. **Layout** (`fillMaxWidth`, `size`)
2. **Appearance** (`background`, `border`)
3. **Interaction** (`clickable`, `pointerInput`)
4. **Animation** (`graphicsLayer`, `animate...`)
> Follows Google’s recommended modifier ordering to prevent hit-box bugs.
## 5. Accessibility
- Always assign `contentDescription` to images.
- Use `semantics {}` to override roles when needed.
- Use `mergeDescendants = true` to combine children if too verbose for screen readers.
## 6. Preview & Theming
- Every public composable must have at least one **`@Preview`** in the same file with default theme.
- Use `MaterialTheme.colorScheme` and `MaterialTheme.typography` for design tokens.
- Avoid hard-coded `dp/sp` values – prefer `dimensionResource` for design specs.
## 7. Parameter Overload & Default Values
- For simple boolean flags, prefer **separate composables** (e.g., `FilledButton`, `OutlinedButton`) over a `filled: Boolean` flag.
- Default values should reflect design specs (e.g., `elevation = ButtonDefaults.elevatedButtonElevation()`).
> **Violating this guideline** should trigger AI warnings or refactoring suggestions during code reviews.
---
Nếu bạn cần mình xuất bản guideline này dưới dạng `.mdc` để dùng trong Cursor AI hay format Markdown đơn giản thì cứ nói nhé.Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

