0Pricing
Kotlin Multiplatform Academy · Lesson

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

  1. A Cross-Platform ViewModel Base
  2. Expose UI State as StateFlow
  3. Handle User Intents & Actions
  4. Bind the ViewModel to Each UI
← Back to Kotlin Multiplatform Academy