How to build a new Compose screen with state hoisting
Quando usar: New screen in a Compose app — get it right the first time rather than refactoring later.
Pré-requisitos
- Android Studio with a recent Compose BOM — Use the latest stable Compose BOM in your build
- Skill cloned — git clone https://github.com/anhvt52/jetpack-compose-skills ~/.claude/skills/jetpack-compose-skills
Fluxo
-
Describe the screenBuild a Profile screen: avatar, name, bio, follow button. State comes from a ProfileViewModel.✓ Copiado→ Stateless composable + stateful wrapper + preview
-
Wire the ViewModelHook up the ViewModel using collectAsStateWithLifecycle.✓ Copiado→ Lifecycle-aware state collection
-
Add a previewAdd @Preview variants for empty, loaded, and error states.✓ Copiado→ Three previews rendering without a live ViewModel
Resultado: A clean Compose screen with previews and a testable structure.
Armadilhas
- Stateful composables you can't preview — Keep the composable stateless; hoist state to a wrapper
- Wrong Modifier order — Skill prompts the order rule — padding before background for a padded background, etc.