MVI Architecture in Kotlin Multiplatform - Part 2
Article Summary
Arkadii Ivanov from Bumble shows how to bridge Kotlin Multiplatform MVI architecture with native iOS and Android UI. The iOS integration reveals surprising complexity that most KMP tutorials skip.
This is part 2 of a 3-part series on implementing MVI architecture in Kotlin Multiplatform. After building shared business logic in part 1, Ivanov tackles the platform-specific implementations—creating data sources with NSURLSession for iOS and HttpURLConnection for Android, then integrating the shared component into SwiftUI and Android Views.
Key Takeaways
- iOS requires proxy classes to bridge Kotlin MVI with SwiftUI's ObservableObject pattern
- Android integration is straightforward using AbstractMviView with RecyclerView and SwipeRefreshLayout
- KittenDataSource uses expect/actual to implement platform-specific networking in shared module
- SwiftUI lifecycle limitations demand ComponentHolder class to manage component destruction properly
Integrating KMP business logic with native UI is simple on Android but requires additional wrapper classes on iOS due to SwiftUI's reactive patterns and Kotlin-Swift interop limitations.
About This Article
Arkadii Ivanov's team needed to build platform-specific networking for the shared Kittens module. They wanted to reuse code across iOS and Android, using iosX64, iosArm64, and androidMain source sets.
They used Kotlin Multiplatform's expect/actual feature to create platform-specific KittenDataSource implementations. iOS used NSURLSession for async operations, while Android used HttpURLConnection with the subscribeOn operator to handle background threading.
A single shared module could now load image URLs from the network on both platforms without duplicating business logic. This reduced maintenance work and let each platform use its native networking patterns.