Hello, I have a question regarding architecture of...
# compose
t
Hello, I have a question regarding architecture of multiplatform project. I understand that it is quite easy to share view models. UI and other platform specific components can be mapped using `expected`/`actual`. Did anybody try to use such a approach for building iOS app? Is that technically even possible? What prevents from creating iOS app in JetPack Compose? For me JetPack Compose seems like great multiplatform development framework but there is a very little info on using it on iOS.
f
This thread (and more) might help. Try searching for "iOS" in this channel
TLDR: No, there is no official support for iOS but Compose (not Compose UI) can technically run on iOS
t
I understand that Compose UI is quite hard to port (they probably don't want to go drawing-to-Canvas approach like Flutter does) but reusing Compose + ViewModels and maintaining only platform specific UI Components could be still improvement comparing to two teams writing everything from schratch for both platforms. Did anybody try this approach for their project?
h
You "just" have to write a wrapper for all Compose UI for UIKit in Kotlin/Objective C. But this is a big task and you can't expect any help from Apple. In fact, you would rewrite SwiftUI in Kotlin based on Compose mechanics. So it is not impossible, but only time consuming. The current alternative splitting you code in a ViewModel module and a compose module for android etc, and use your VM module with iOS and write your UI with SwiftUI is a lot faster.
a
The simpler and more realistic way is to share the layers except UI and leave Compose UI and SwiftUI as two different parts. There should be some examples if you do some search.
☝️ 4
k
@Tomáš Hubálek there is a project that attempts to do what you described: https://github.com/cl3m/multiplatform-compose but it hasn’t been updated for some time already However I can agree that sharing everything up to ViewModel that is emitting current ui state and consuming it in Jetpack Compose/SwitUI is a better idea
j
My problem with sharing the viewmodel is I want to use combine in iOS and stateflow or flow in Android. I prefer to keep the UI and VM in the same layer for iOS and Android.
t
Thanks for all your inputs.