I am working on a kmm library that has UI elements...
# multiplatform
l
I am working on a kmm library that has UI elements at work. Right now, I’m using UIKit written in Kotlin for the UI on iOS, which allows me to have my logic and UI in the same codebase. I’m currently in the process of migrating the UI from the Android side to Compose, and was wondering if anyone’s used SwiftUI + KMM for a library. I know for a final app, it’s common to use SwiftUI in the app sources, but would this work just as well for a library, or are there any gotchas I may run into?
k
The SwiftUI obviously needs to be in Swift, so you’d need to be able to distribute the Swift code. We so something like this with a client. It’s not SwiftUI, but the UI is written in Swift, and requires distributing both the Kotlin-generated framework and a UI framework that has the Swift code and depends on the Kotlin one.
l
I figured it would probably be two frameworks. I heard from one of the iOS devs on my team that layering frameworks isn't easy to do for iOS in a way that won't break. Have y'all had a good experience with that?
k
We didn’t “layer” them. One depends on another. Not sure what they mean by layering. I assume that means one is embedded in the other, which we also found brittle and don’t do.
In our case, it’s a private sdk, and we could support just SPM, so it was easier than, say, a public sdk.
l
That makes sense. I'll take a look at maybe restructuring for SwiftUI. I was also taking a look at Compose for iOS so I could share the code with Android, but it looks like it's not near ready yet. I was kind of hoping to maintain the UIKit until CfI is ready.
k
Native compose is for sure not ready. There is progress, but it’ll be a while.
l
I'll likely switch most of my iOS UI code over to compose when it's stable, but I need something I can rely on until then. It looks like SwiftUI is the move until then.
r
Personally, I'd want to keep UI work out of KMM so I could continue to use the UI Canvas feature in Xcode. Canvas is such a huge boost to productivity.
k
We don’t do any iOS UI in Kotlin, generally speaking. I think with Compose on native we’ll probably do some blended, but I’m guessing it’ll be a while before we do complete apps like that.