https://kotlinlang.org logo
#compose-ios
Title
# compose-ios
s

Solomon Opoku

12/12/2023, 7:17 PM
Hi guys , i just started my mulitplatform journey. Working on an app in KMP and initially the plan was to keep ui for android in compose and ios in swift ui . but i am looking to do everything in compose KMP . the android side of the app has been done and i am wondering how i can move the UI to the ios side since i started the project as a KMP one and not compose KMP . should i create a new compose KMP and start moving my files or is there a better way to port an existing KMP to Compose KMP . Any help will be appreciated . Thanks
s

Solomon Opoku

12/12/2023, 7:46 PM
Thanks a lot @Joel Denke
j

Joel Denke

12/12/2023, 7:50 PM
In most cases I think can share almost everything between iOS and Android but depends what you had before. But already having it as KMP I think is easier compared to having two completely separate iOS and Android native apps.
CMP mostly has interop with Swift ui and objc, so it works mixing as well. Can do partial migration.
s

Solomon Opoku

12/12/2023, 7:58 PM
@Joel Denke I already have the network layer and some of the business logic in the shared module . Ui for android has been built with compose and i am using voyager for navigation , koin for DI and the android viewmodel class to handle state. I was gonna work on the ios equivalent of the UI but i wanted to take the opportunity to share the UI i have already built instead of doing one from scratch . so that is why i wanted to find, do i just move the already built compose ui in to the shared module for that to happen ?
j

Joel Denke

12/13/2023, 7:31 AM
You need to decouple Android viewmodels from iOS worth mentioning. If already having shared stuff probably can just create iosApp and try export the shared module to iOS. Then just create ui compose view controller that holds as reference entry point to compose root level. I created a solution where sharing 100% compose in iOS and Android. My advice, test first create a new root compose host and share with iosApp and androidApp. Provided in article mentioned. Once it runs fine, test migrate one part at the time imo. But need to considering compose resources to share fonts, images etc across shared module. In most cases you should be able just take what you already have but in some need expect/actual, or frameworks decouple differences in iOS vs Android. For ui only, iOS and Android material and material 3 as well as all other things except live preview should work. Live preview work if used in androidMain only but not if common because iOS limitations.
4 Views