I just want to share a little KMM success story, i...
# multiplatform
b
I just want to share a little KMM success story, if anyone is interested! A little while ago I joined a small company as their sole Android developer. They were writing essentially the same app in 3 codebases, one for Android (Java), iOS (ObjC), and JavaScript. The three of us would coordinate changes between the three code bases. Since joining, I rewrote the entire Android app in Kotlin, integrated kotlin multiplatform, and added Web (written in Kotlin) and iOS (written in Swift) view layers. I now ship Android, Web, and iOS clients myself, all from one codebase, turning 3 developer's jobs into one! They are pretty happy with the outcome. Our current breakdown is about 65% common code / 35% platform code. Thank you Kotlin devs and Jetbrains for such an amazing tool 🙂
👌 11
🎉 18
K 19
l
Thanks for sharing mate! Its good to hear success stories, this is what KMM is built for!
j
@Brian G is there anything you can share re. architecture you're using and what parts are shared (e.g. is ViewModel, if used, in shared or platform code?)
👍 2
1
u
are size, time to render, etc. an issue for you regarding your web app?
b
are size, time to render, etc. an issue for you regarding your web app?
@uli Yes, that is my #1 complaint with Kotlin/JS. Our production JS bundle comes in at a whopping 5.23mb! It can take a second or two to execute even when cached (I show an animated "splash" screen during this time). For our use case, this is acceptible but I would love to optimize it.
@John O'Reilly Yes. We use our own variant of "server-driven UI" where the the server sends JSON down to that client that defines all the screens, navigation, behaviour (e.g. https://www.judo.app/blog/server-driven-ui/). This was already the case when I joined the company (they've been doing it for ~10 years). But it's the perfect use case for Kotlin because all the code to handle that protocol was duplicated across the 3 clients.
👍 1
So the core app is entirely in the common code, and exposes the UI as an ever-changing tree of view models (e.g.
Flow<ViewModel>
). Each client is only responsible for rendering the view models. In our architecture, layout (margins/paddings/colors/children/etc.) is all part of the view model.
I also have cross-platform interfaces for native APIs like permissions, geofencing, etc.. (If I had the time, I would love to clean those up and publish them as kotlin multiplatform libraries)
And I use these awesome multiplatform libraries currently in commonMain:
Copy code
implementation(kotlin("stdlib-common"))
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:$serialization_version")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$serialization_version")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version")
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.3.0")
implementation("io.ktor:ktor-client-core:$ktor_version")
implementation("io.ktor:ktor-client-json:$ktor_version")
implementation("io.ktor:ktor-client-serialization:$ktor_version")
implementation("org.jetbrains.kotlinx:atomicfu:${Versions.KOTLINX_ATOMICFU}")
implementation("co.touchlab:stately-isolate:1.1.10-a1")