From the course: Exploring Ktor with Kotlin Multiplatform and Compose
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Compose UI architecture - Kotlin Tutorial
From the course: Exploring Ktor with Kotlin Multiplatform and Compose
Compose UI architecture
- [Instructor] Now that we have built a shared network and business layer, it's time to put it to work in the UI. In this chapter, we're focusing in on composed UI side of things, starting with architecture. Open up the compose app module. This is where our composed multi-platform UI code lives. The architecture here follows the MVVM pattern. With unit directional data flow, state flows down from the view models, events bubble up from the UI. Take a look at APOD view model to see how the view model talks to the repository and emits state through state flow. Inside the view model, we use Kotlin routines to fetch data and update state. When something goes wrong, say a network error. We update the state to reflect the error and the UI reacts accordingly. This keeps the business logic out of the composable. Take a look at the today screen, to see how UI renders whatever state it receives and sends users events back to the view model. This pattern helps us stay organized as apps grow, you…