Karan Dhillon, 12 May 2021KMM with Jetpack Composeand Swift UIBuild declarative UIs with maximum code sharing
View Slide
Issue with KMM plugin on AS 4.2
dependencies {classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.0-release-764")classpath("com.android.tools.build:gradle:4.2.0")}
dependencies {classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.0")classpath("com.android.tools.build:gradle:4.2.0")}
Meet the new kids on the block
• KMM - Kotlin Multiplatform Mobile• Jetpack Compose - Android’s modern toolkit for building native UI• SwiftUI - UI toolkit by Apple to design apps in a declarative manner
KMM - KMP, but more emphasison mobile
Important bitsA Kotlin Mobile Multiplatform project consists of three components:• Shared module• Android application• iOS application
Shared module (buildscript)
Meet the project
Shared module (buildscript) Root module (buildscript)
Goal : create a facade over networking andcache service
Goal : create a facade over networking andcache serviceFirst, lets take care of networking
Now, we create the cache service
By default, SQLDelight plugin reads .sq files from thesqldelight folderWe create the package specified in the packageNameparameterInside it, we create the .sq file with the name of ourdatabase
AppDatabase.sq
To initialize AppDatabase, we needs to pass anSqlDriver instance to it
DatabaseDriverFactory (commonMain)
DatabaseDriverFactory (androidMain)
DatabaseDriverFactory (iosMain)
Now that we have a SqlDriverFactory, we canproceed with initializing AppDatabase
Database (commonMain)
With networking and cache service done, wecan finally create our facade
SpaceXSDK (commonMain)
Time for jetpack compose
build.gradle.kts (androidApp)
MainActivity (androidApp)
Building with SwiftUI
RocketLaunchRow.swift (iosApp)
Pros (and Cons?)
Pros (and Cons?)• Maximum code sharing• Expect/Actual pattern• Concurrency in Kotlin/Native• Single framework for shared module
Contact• Twitter: @karandhillon95• Blog: https://kdhillon.com