Uploading images in Kotlin Multiplatform
I’ve been working on sharing logic between Android and iOS and I’d like to share my experience with working with images in a platform agnostic way.
Introduction
Kotlin Multiplatform lets you share non platform specific logic ( “non UI code”) between different platforms (Android, jvm, js, iOS, macOS, etc…) and gives you the possibility of creating abstractions over platform specific logic.
I won’t dive into more detail about the technology, you can read more about it here.
Context
The feature was about uploading an application, with an icon and screenshots. Check out the final versions:
Additionally my goal was to test out Kotlin Multiplatform with the following technical decisions:
- A shared ViewModel layer
- Unidirectional data flow
Practically this means, that all the icons, screenshots you see above will be part of the state stored in a shared ViewModel, with the following events:
- All platforms submit their platform specific representation of the selected image
- The ViewModel works with these images in a platform agnostic way
- All platforms receive back the platform specific…