Bind the ViewModel to Each UI
Connect shared state to Compose and SwiftUI.
The Last Mile
Your shared ViewModel is ready. Now each native UI just needs to observe its state and forward user intents. That is the final wiring.
Compose Collects State
On Android, use collectAsState to turn the StateFlow into Compose state. Every emission recomposes the screen automatically.
val state by viewModel.state.collectAsState()All lessons in this course
- A Cross-Platform ViewModel Base
- Expose UI State as StateFlow
- Handle User Intents & Actions
- Bind the ViewModel to Each UI