State holders and state production in the UI Layer
summary
Recommendation: use a ViewModel as the screen-level state holder to keep business logic and screen UI state, use viewModelScope for long-running requests and to survive configuration changes, and avoid holding Context or passing ViewModels around. Use plain state holder classes for reusable UI element logic (example: DrawerState delegating to swipeableState). Produce UI state with MutableStateFlow/StateFlow, use combine() to merge local and external streams and stateIn(viewModelScope, WhileSubscribed, 5 seconds), then collect with collectAsStateWithLifecycle.
AI-written summary · about
chapters (16)
- 0:00Introduction
- 1:37Types of UI state
- 2:24Types of logic
- 4:25How state and logic relate to each other
- 4:50Where to handle logic
- 5:10ViewModels
- 8:55Plain state holder classes
- 11:35Identifying state holders in the UI
- 13:08Should you use ViewModels?
- 14:20Producing screen UI state
- 15:03Local sources of state change
- 16:07External sources of state change
- 16:56Combining local and external sources
- 18:15Collect state in a lifecycle-aware manner
- 18:40Modelling screen UI state based on inputs
- 19:34Recap








