|
| 1 | +# Contributing |
| 2 | + |
| 3 | +Thanks for considering a contribution. The cookbook has a deliberately narrow scope: a small, curated set of canonical Compose modifiers, all built on `Modifier.Node`. We'd rather ship 12 great modifiers than 50 mediocre ones. |
| 4 | + |
| 5 | +## Before you start |
| 6 | + |
| 7 | +- Open an issue first if you're proposing a new modifier. We'll talk through scope, name, and whether it belongs in `cookbook` (general-purpose) or somewhere else. |
| 8 | +- Bug fixes and doc improvements: jump straight to a PR. |
| 9 | + |
| 10 | +## The bar for a new modifier |
| 11 | + |
| 12 | +Every modifier in the cookbook ships: |
| 13 | + |
| 14 | +1. **A `Modifier.xxx(...)` extension** that validates inputs and returns `this then SomeElement(...)`. |
| 15 | +2. **A `ModifierNodeElement` subclass** as a `data class` (so `equals`/`hashCode` are correct), with a meaningful `update()` that mutates the existing node, never recreates. |
| 16 | +3. **A node class** mixing in the right `Modifier.Node` mixin(s). Pick the cheapest mixin that does the job. |
| 17 | +4. **KDoc** on the public function: paragraph description, parameter docs, a `@sample` reference to a sample function in `cookbook/.../samples/`. |
| 18 | +5. **A unit test** in `cookbook/src/test/...`. Use `createComposeRule` + Robolectric. Cover at minimum: parameter validation, parameter-change-without-recreation, and one behaviour assertion. |
| 19 | +6. **A sample-app screen** in `sample/.../screens/` and entry in `CookbookCatalog.catalogEntries()`. |
| 20 | +7. **A doc page** in `docs/modifiers/<name>.md` with usage, parameters, and design notes (which node subtype, why, any subtleties). |
| 21 | + |
| 22 | +## Quality gates |
| 23 | + |
| 24 | +The CI build must be green. Locally: |
| 25 | + |
| 26 | +```bash |
| 27 | +./gradlew build |
| 28 | +``` |
| 29 | + |
| 30 | +That runs `ktlint`, `detekt`, lint, unit tests, and assembles both modules. |
| 31 | + |
| 32 | +Conventions: |
| 33 | + |
| 34 | +- **No `Modifier.composed`** anywhere in `cookbook/`. That's the entire point of the project. |
| 35 | +- **No `LaunchedEffect`** in modifier impls; use the node's `coroutineScope`. |
| 36 | +- **No reflection.** No `kotlin-reflect`, no `Class.forName`. |
| 37 | +- **Public API is `@Stable`** (or `@Immutable` for value classes). |
| 38 | +- **`explicitApi()` is on** in `cookbook`: every public symbol needs an explicit visibility modifier. |
| 39 | +- Animations driven by `Animatable` / `AnimationState`, cancelled implicitly by node detach. |
| 40 | + |
| 41 | +## Repo secrets (for maintainers) |
| 42 | + |
| 43 | +Publishing to Maven Central is wired through GitHub Actions and reads these repo secrets: |
| 44 | + |
| 45 | +| Secret | Purpose | |
| 46 | +|---|---| |
| 47 | +| `MAVEN_CENTRAL_USERNAME` | Central Portal user token name | |
| 48 | +| `MAVEN_CENTRAL_PASSWORD` | Central Portal user token password | |
| 49 | +| `SIGNING_IN_MEMORY_KEY` | ASCII-armored private GPG key (`gpg --armor --export-secret-keys <KEY_ID>`) | |
| 50 | +| `SIGNING_IN_MEMORY_KEY_ID` | The 8-character short key ID (e.g. `0A1B2C3D`) | |
| 51 | +| `SIGNING_IN_MEMORY_KEY_PASSWORD` | Passphrase for the GPG key | |
| 52 | + |
| 53 | +Pushing a `vX.Y.Z` tag triggers `.github/workflows/publish.yml`, which strips `-SNAPSHOT` from `gradle.properties`, signs, and uploads to the Central Portal staging bundle (auto-released). |
| 54 | + |
| 55 | +## Style |
| 56 | + |
| 57 | +- Kotlin official style. ktlint enforces. |
| 58 | +- `data class` for elements; small `internal class` for the node. |
| 59 | +- Names: file = `Xxx.kt` (PascalCase), package = `xxx` (all lowercase, no separators), public function = `Modifier.xxx` (camelCase). |
| 60 | +- Tests: `xxx_does_yyy()` (snake_case method names; backticks-with-spaces are nicer to read but ktlint and the Robolectric runner complain about characters like `[`/`]`). |
| 61 | + |
| 62 | +## License |
| 63 | + |
| 64 | +By contributing you agree your contribution is licensed under the Apache 2.0 License. |
0 commit comments