In previous posts I’ve used GalwayBus repo to illustrate results of various explorations I’ve done in to the use of Kotlin Multiplatform. However I thought there’d be value in creating a more minimal project that would allow clearer illustration of key moving parts of a multiplatform project and thus PeopleInSpace was created. It also provided opportunity to try out use of Jetpack Compose for the Android app (with UI being developed on iOS using SwiftUI - using pretty much same approach outlined in SwiftUI meets Kotlin Multiplatform!).
The project uses very basic API to show list of people currently in space (inspired by https://kousenit.org/2019/12/19/a-few-astronomical-examples-in-kotlin/)!
Note: You need to use Android Studio v4.0 (currently on Canary 6) to build Android app. Have used XCode v11.3 to build iOS app.
The Kotlin/Swift code below constitutes majority of code used in the project (I did say it was minimal!!). The project also makes use of:
- Kotlin Coroutines
- Kotlinx Serialization
- Ktor client library
- Android Architecture Components (primarily
ViewModel
) - Koin
As always, PRs or suggestions for better way of implementing any of this are very welcome (can respond to tweet shown at bottom of post)!
iOS SwiftUI Code
iOS Swift View Model
Android Jetpack Compose code
Android Kotlin ViewModel
Shared Kotlin Repository
It would be preferable if PeopleInSpaceApi
instance used here could also be injected using Koin. I believe there’s work ongoing to allow use of Koin
in a multiplatform project….will update this if/when that become available.
Shared Kotlin API Client Code (using Ktor and Kotlinx Serialization library)
Update 26/12/2019
Added commit that starts to make use of new Kotlin/Native multi-threaded coroutine support (1.3.3-native-mt
preview version)
outlined in https://github.com/Kotlin/kotlinx.coroutines/issues/462
Featured in Kotlin Weekly Issue #178
Related tweet
Just created new minimal #KotlinMultiplatform sample -https://t.co/RjvKxaMjMG. Includes use of:
— John O'Reilly (@joreilly) December 22, 2019
-SwiftUI
-Jetpack Compose
-Android ViewModel
-Koin
(article below provided inspiration for "People In Space" API I used - thanks @kenkousen!) https://t.co/GyN3HOO8e4