Hi all, I have a KMP project which is supporting i...
# multiplatform
g
Hi all, I have a KMP project which is supporting iOS and Android, for iOS I have a native UI component in SwiftUI, however I am importing a ViewModel from the common Kotlin code using the approach described here. In order for the ViewModel to be available in the public API of the XCFramework, I have not added any visibility modifier to the ViewModel so it is by default public. For Android the UI component is built into the KMP library using Compose. I would like to avoid making the common ViewModel available in the public API for Android, as users will just import the UI component, while still sharing the ViewModel across the two platforms, can anyone recommend an approach or is this not possible?
f
I guess, you need to put the UI part of your Android compose inside another module
You need to have a shared module containing only the shareable code between iOS and Android
g
Ok thanks let me explore that, I've been separating the non public code into another module and importing that into the public module, so separating the Compose code further that would still allow me to export ViewModel publicly for iOS
f
Using explicitAPI is very usefull when sharing native code (almost mandatory)
(build performance, binary size, ...)
For iOS (until swift export): you only have an umbrella module with what you need to expose on iOS side.
If you plan to migrate to CMP for iOS. Use the CMP ViewModel instead of Android/KMP ViewModel
g
As this library is for third parties to use, it has to support natively built apps, but I will look at feasibility of CMP as well
Will definitely use explicitAPI thanks