/engsys-kotlin:jetpack-composefrom engsys-kotlin
Build Android UIs with Jetpack Compose: composition, state hoisting, remember/rememberSaveable/derivedStateOf, recomposition correctness and performance, side-effect APIs (LaunchedEffect/DisposableEffect/rememberCoroutineScope/produceState/snapshotFlow), Material 3 theming, and Compose navigation. Use when writing or reviewing @Composable functions, fixing recomposition or state bugs, hoisting state, choosing a side-effect API, applying Material 3, or improving Compose performance and stability.
Ships in engsys-kotlin. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Build and review Android UIs with Jetpack Compose targeting the current Compose BOM (2025.x) and Material 3. Composables are pure descriptions of UI for a given state; the runtime re-invokes them (recomposes) when the state they read changes. Treat composition as a function of state, keep composables side-effect free except through the official effect APIs, and hoist state so UI is testable and reusable. This is Android's analogue of declarative SwiftUI.
@Composable function emits UI. It may run often, in any order, in parallel,
and be skipped. It must be idempotent and free of side effects.State<T> /
MutableState<T>). Reading a state value subscribes that composition scope to
it; when it changes, only scopes that read it recompose.| API | Use for |
|---|---|
remember { } | Keep an object across recompositions (not config changes). |
rememberSaveable { } | Survive config changes and process death (Bundle-able). |
mutableStateOf(x) | Observable state that triggers recomposition on change. |
derivedStateOf { } | Computed state derived from other state (see below). |
produceState | Convert non-Compose async source into State. |
@Composable
fun Counter() {
var count by rememberSaveable { mutableStateOf(0) } // survives rotation
Button(onClick = { count++ }) { Text("Count: $count") }
}
by delegation (var x by remember { mutableStateOf(...) }) for ergonomic
reads/writes.remember(key1, key2) { ... } recomputes when a key changes — use keys to
reset remembered state when inputs change.rememberSaveable for anything the user would be annoyed to lose on
rotation (text input, scroll selection, expanded state).Make composables stateless by lifting state up to the caller. A hoisted composable takes the value as a parameter and exposes changes via a callback — the "state down, events up" pattern.
// Stateless, reusable, testable
@Composable
fun SearchField(query: String, onQueryChange: (String) -> Unit) {
TextField(value = query, onValueChange = onQueryChange)
}
// Stateful caller owns the state
@Composable
fun SearchScreen(viewModel: SearchViewModel) {
val state by viewModel.uiState.collectAsStateWithLifecycle()
SearchField(query = state.query, onQueryChange = viewModel::onQueryChange)
}
Hoist to the lowest common ancestor that needs the state. State that belongs to
the screen's logic lives in the ViewModel; ephemeral UI state (animations,
focus, scroll) can stay local with remember.
Use derivedStateOf when state should be computed from other state and you
want to recompute only when the result changes, not on every read of the
inputs. The classic case: deriving a boolean from a frequently changing value.
val listState = rememberLazyListState()
// Recomposes only when the boolean flips, not on every scroll pixel.
val showButton by remember {
derivedStateOf { listState.firstVisibleItemIndex > 0 }
}
Do not use derivedStateOf for a plain transformation of a single state that
changes at the same rate as the result (e.g. val upper = text.uppercase()) —
that is just a normal calculation and the extra machinery is wasteful.
{ offset } rather than offset) for high-frequency values like scroll/drag.viewModel::onClick) where possible.Modifier ordering matters — order changes layout and draw; it is not
commutative.key in LazyColumn/LazyRow items(list, key = {...})
so items keep identity across data changes (analogous to a stable
Identifiable id).Choose the narrowest effect that fits:
| API | When |
|---|---|
LaunchedEffect(key) | Run a suspend function when entering composition / when key changes; cancelled on leave. |
rememberCoroutineScope() | Launch coroutines from event callbacks (button clicks), not composition. |
DisposableEffect(key) | Register/unregister non-suspend resources; onDispose { } cleans up. |
SideEffect { } | Publish Compose state to non-Compose code after every successful recomposition. |
produceState | Turn a callback/Flow source into observable State. |
snapshotFlow { } | Convert reads of snapshot state into a cold Flow. |
rememberUpdatedState | Capture the latest value inside a long-lived effect without restarting it. |
// Run once on enter (key = Unit), re-run when userId changes:
LaunchedEffect(userId) {
viewModel.load(userId) // suspend; auto-cancelled on leave/key change
}
// Observe a lifecycle/listener and clean it up:
DisposableEffect(lifecycleOwner) {
val observer = LifecycleEventObserver { _, e -> handle(e) }
lifecycleOwner.lifecycle.addObserver(observer)
onDispose { lifecycleOwner.lifecycle.removeObserver(observer) }
}
// React to snapshot state as a flow:
LaunchedEffect(listState) {
snapshotFlow { listState.firstVisibleItemIndex }
.distinctUntilChanged()
.collect { analytics.logScroll(it) }
}
Rules:
key of LaunchedEffect/DisposableEffect controls restart. Use a stable,
meaningful key — never Unit if the work depends on a changing input.LaunchedEffect (tied to
composition) or rememberCoroutineScope (tied to events).rememberUpdatedState to read the freshest callback inside a
LaunchedEffect(Unit) that should not restart.Always collect with lifecycle awareness so collection stops in the background:
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
collectAsStateWithLifecycle() (from lifecycle-runtime-compose) is preferred
over collectAsState() on Android — it stops collecting when the lifecycle drops
below STARTED, avoiding wasted work and leaks.
data classes,
primitives, and @Immutable/@Stable-annotated types.List<T> is treated as unstable. Prefer kotlinx.collections.immutable
(ImmutableList/PersistentList) for list parameters, or wrap in a @Immutable
holder.LazyColumn/LazyRow/LazyVerticalGrid for large/scrolling collections;
never render large lists with a Column inside a verticalScroll.Modifier.composed { } for new code; prefer Modifier.Node based
modifiers for custom modifiers.Use androidx.compose.material3 (Material 3 / Material You) for new UIs.
@Composable
fun AppTheme(content: @Composable () -> Unit) {
val dark = isSystemInDarkTheme()
val colors = if (supportsDynamicColor() && dark) {
dynamicDarkColorScheme(LocalContext.current) // Material You, Android 12+
} else if (dark) darkColorScheme() else lightColorScheme()
MaterialTheme(colorScheme = colors, typography = AppTypography, content = content)
}
MaterialTheme (colorScheme, typography, shapes); read
values via MaterialTheme.colorScheme.* rather than hardcoding colors.dynamicLightColorScheme /
dynamicDarkColorScheme where the product wants Material You.Scaffold, TopAppBar, NavigationBar,
FilledTonalButton, etc.) and honor WindowInsets / edge-to-edge.ViewModel with viewModel() (or Hilt's hiltViewModel()).StateFlow; collect with
collectAsStateWithLifecycle().ViewModel). Keep
composables free of business logic.NavHost/NavController) or Navigation 3 if the
project has adopted it; hoist the NavController to the app root.collectAsState() instead of collectAsStateWithLifecycle() on Android.key in lazy list items — breaks item identity and animations.derivedStateOf for a 1:1 transform — unnecessary; just compute it.remember where rememberSaveable is needed — state lost on rotation.LaunchedEffect/event scope.LaunchedEffect(Unit) that depends on a changing value — stale captures;
key it properly or use rememberUpdatedState.List, lambdas allocated inline) defeating skipping.Column instead of LazyColumn.rememberSaveable used for state that must survive config changesderivedStateOf used only for derived state that changes less than inputscollectAsStateWithLifecycle()LaunchedEffect/DisposableEffect keyed correctly; resources disposedrememberCoroutineScope, not bodykeysMaterialTheme; dynamic color where wantedWhat SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub eric-sabe/engsys --plugin engsys-kotlin3 skills in this plugin
/android-testingWrite and review Android/Kotlin tests across the pyramid: JUnit (4/5) unit tests, MockK, Turbine for Flow/StateFlow assertions, coroutine testing with runTest and test dispatchers, Robolectric JVM tests, Espresso instrumented UI tests, and Compose UI testing with createComposeRule and semantics matchers. Use when writing or fixing unit tests, testing coroutines/Flows, mocking dependencies, choosing JVM vs instrumented tests, or testing Compose UI and ViewModels on Android./kotlin-coroutinesWrite data-safe asynchronous Kotlin with coroutines, Flow, and structured concurrency on Android. Use when fixing coroutine cancellation or leak bugs, choosing dispatchers (Default/IO/Main), designing suspend functions, modeling streams with Flow/StateFlow/SharedFlow, scoping work to viewModelScope/lifecycleScope, handling exceptions with CoroutineExceptionHandler/supervisorScope, or converting callback/RxJava APIs to coroutines. Covers Kotlin 2.x, kotlinx.coroutines structured concurrency discipline, and the Android main-safety contract.