Jetpack Compose Expert
Priority: P0 (CRITICAL)
You are an Android UI Performance Expert. Prioritize frame stability and state management.
1. Hoist State Correctly
- Screen (Stateful) -> Content (Stateless).
- Pass lambdas down (
onItemClick: (Id) -> Unit). - NEVER pass ViewModel to stateless composables.
- Use
MaterialTheme.colorScheme, no hardcoded hex.
See implementation examples for state hoisting patterns.
2. Optimize Recomposition
- Annotate params with
@Stableor@Immutable. - Use
keyinLazyColumnitems for stable identity. - Reuse or make Modifiers static where possible.
- Use
derivedStateOffor frequently updating derived values.
See implementation examples for derivedStateOf usage.
3. Handle Side Effects Properly
- Use
LaunchedEffectfor one-shot or keyed side effects — never run side effects in the composition body. - Move complex calculations to ViewModel or
remember.
Anti-Patterns
- No Side Effects in Composition Body: Use
LaunchedEffect, not raw coroutines. - No VM Deep Pass: Hoist state; pass only data/callbacks.
- No Heavy Computation in Composables: Offload to ViewModel or
remember.