https://kotlinlang.org logo
n

Norbi

07/20/2022, 11:04 AM
Does anyone know: is it possible to write iOS UIs using KMM + Compose/Multiplatform? Or is it necessary to write Swift code for iOS UIs? Thanks.
b

Big Chungus

07/20/2022, 11:09 AM
It's possible with unanounced experimental canvas api being worked on.
😮 1
Scroll up #compose-desktop channel for threads of people discussing it
👍🏻 1
🙏 1
n

Norbi

07/20/2022, 11:27 AM
+ I've just found this channel, thanks 😉 : #compose-ios
🎉 3
l

Landry Norris

07/20/2022, 2:04 PM
Compose for iOS is still not quite ready for production, but it’s making a lot of progress. I’m hoping it will be ready in the next several months.
👍🏻 1
I mainly work on libraries, so it’s kind of frustrating that I get a compiler exception when I try to compile Compose in an iOS framework, but they should be fixing that before release. I think they’re trying to get things like keyboard done first before making the build process stable.
😐 1
r

ribesg

07/21/2022, 7:46 AM
It's not necessary to write any Swift code for iOS UIs, you can use UIKit in Kotlin.
😮 2
true story 1
l

Landry Norris

07/21/2022, 1:53 PM
Would not recommend. UIKit is so different from Android's views that it gets hard to deal with both. Compose/SwiftUI are a much better pair.
r

ribesg

07/21/2022, 2:51 PM
UIKit isn't any harder to use than Android Views. It's different but still closer to each other than any of them compared to a web framework. Compose and SwiftUI are obviously much closer to each other as they're basically copies of React. But I prefer having to use 2 different UI frameworks than 2 different languages. My brain can't handle switching language multiple times a day, Kotlin and Swift are too close.
I have a 2.5yo iOS app in production which does not and never contained any Swift or Obj-C code. Just 50k+ lines of pure Kotlin.
😮 1
l

Landry Norris

07/21/2022, 2:54 PM
That’s a good way to put it. I generally prefer SwiftUI, because you don’t need to write ‘real Swift’ (no logic) as opposed to switching between Android view and UIKit. I migrated a complex legacy Android/iOS project pair to one KMM project lately, so we used UIKit so we could just translate, and the differences between Android views and UIKit are the biggest slowdown when I work on that.
r

ribesg

07/21/2022, 3:03 PM
Yeah I see what you mean. I completely agree that when using Android Views and UIKit you make your UI twice. You don't really gain anything. When using Compose/SwiftUI you reuse mostly the same ideas. It's more about translating. In my case I only have an iOS app. It relies on dozens of KMP libraries (algorithms, utils, API clients, etc.) so I just decided to stop using anything but Kotlin and made the app itself in Kotlin. It completely erased any kind of interop problem. No converting between Kotlin and Swift types, coroutines everywhere, etc. All the good stuff. I made my own microframework that wraps UIKit, at least the painful parts (defining constraints is pretty cool when you make a little DSL). It's fun and that's great
👍🏻 1
l

Landry Norris

07/21/2022, 3:04 PM
That makes sense. I’d probably do the same in that case since you don’t have to worry about cross-platform compatibility.
m

Michael Paus

07/21/2022, 3:17 PM
The original question was “to write iOS UIs using KMM + Compose/Multiplatform”. The question was not whether to use Swift or UIKit directly. According to the examples, the iOS Compose (Canvas) rendering approach seems to be somehow based on UIKit though. At least the target is called “uikitMain”.
l

Landry Norris

07/21/2022, 3:18 PM
It is built using a SkikoUIView, which is a part of the Jetbrains Skiko library. This library allows rendering to a UIView in a way that is compatible with Skiko. As such, Compose is just an abstraction for rendering onto a single UIView.
r

ribesg

07/21/2022, 3:18 PM
I answered to "is it necessary to write Swift code for iOS UIs?", that's it.
👍🏻 1
l

Landry Norris

07/21/2022, 3:21 PM
There were some previous projects that I would argue better match the title ‘UIKit’ for Compose. These projects would use the Compose tree to layout and render actual UIKit views, meaning each composable roughly correlated with a UIKit view, similar to how Compose for Web currently works to my understanding. Compose UI, however, just uses the platform view system as a single canvas.
r

ribesg

07/21/2022, 3:29 PM
Isn't the current plan to do just that everywhere but on Android? I know it's the plan for iOS and WASM, and maybe for Web
l

Landry Norris

07/21/2022, 3:31 PM
I think the current plan is to use the single canvas method, same as Android. I could be wrong, but that’s the direction the experimental new Compose for Web is going and how iOS/macOS currently are going.
On Android, Compose uses Android’s Bitmap library, which uses Skia under the hood. The others seem to use Skiko, which is the JB wrapper for Skia.
n

Norbi

07/21/2022, 10:00 PM
Thanks for the detailed answers 🙂
70 Views