agentleFS
moclam1905moclam1905/CocktailRecipes/.cursor/rules/ui-rules/compose_ui_guideline.mdc

CocktailRecipes / ui-rules

Cursor rule1 starsChanged 20 months agoMITView on GitHub

UI Guideline: Jetpack Compose coding standards & component conventions

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
  1. Very specific:

    Section/Container: use suffix Section or Container for layout-only groupings.

    line 16
  2. Distinctive:

    Callback parameters: should always be placed last (per Kotlin coding style).

    line 17
  3. Very specific:

    modifier: should come first after data-state params to enable readable chaining.

    line 31
  4. Distinctive:

    Avoid nullable parameters that mean “off” – provide meaningful default values instead.

    line 32
  5. Very specific:

    Use rememberSaveable for states that need to survive configuration changes.

    line 38
  6. Very specific:

    Always assign contentDescription to images.

    line 51
  7. Very specific:

    Use semantics {} to override roles when needed.

    line 52
  8. Very specific:

    Use mergeDescendants = true to combine children if too verbose for screen readers.

    line 53
  9. Very specific:

    Every public composable must have at least one @Preview in the same file with default theme.

    line 57
  10. Very specific:

    Use MaterialTheme.colorScheme and MaterialTheme.typography for design tokens.

    line 58
  11. Very specific:

    Avoid hard-coded dp/sp values – prefer dimensionResource for design specs.

    line 59
  12. Very specific:

    Default values should reflect design specs (e.g., elevation = ButtonDefaults.elevatedButtonElevation()).

    line 64

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
compose_ui_guideline.mdc
---
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é.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.