| name | android-jetpack-compose |
| description | Use when creating, refactoring, or optimizing Android UI components using Jetpack Compose. |
| category | development |
| risk | low |
| source | community |
| date_added | 2026-03-31 |
| metadata | {"triggers":["@jetpack-compose","compose-ui","build-screen","material-3","composable"]} |
Android Jetpack Compose Excellence 🎨
Expert guidance for building modern, high-performance Android UI with Jetpack Compose.
⚡ When to Use
- New Feature UI: Starting a new screen or custom component.
- UI Refactoring: Moving from XML to Compose or legacy Compose to modern patterns.
- Theming: Implementing Material 3, Dark Mode, or Custom Design Systems.
- Performance Fixes: Debugging recomposition issues or laggy lists.
- Animations: Adding smooth transitions and micro-interactions.
🏗️ Core Principles
1. State Management (Hoisting)
- Rule: Composables should be stateless where possible. Hoist state to the caller.
- Bad:
@Composable
fun SearchBar() {
val text = remember { mutableStateOf("") }
TextField(value = text.value, onValueChange = { text.value = it })
}
- Good:
@Composable
fun SearchBar(
query: String,
onQueryChange: (String) -> Unit
) {
TextField(value = query, onValueChange = onQueryChange)
}
2. Slot API Pattern
3. Material 3 (M3)
- Always prefer
androidx.compose.material3 components.
- Use
ColorScheme, Typography, and Shapes from the theme.
🚀 Performance Checklist
🎨 Animations
AnimatedVisibility: For simple appear/disappear.
animateColorAsState: For smooth color changes.
Transition: For complex, multi-state animations.
Lottie: Use lottie-compose for complex vector animations.
🧪 Testing and Previews
- Previews: Use
@Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES) for dark mode testing.
- Multi-device Previews: Use
@PreviewScreenSizes and @PreviewFontScales.
- UI Testing: Use
createComposeRule() and onNodeWithTag().
🔗 Related Resources