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

mohamed rejeb

10/06/2023, 11:56 AM
How to show image in SwiftUi from an image resource in common module without Moko and without CMP
👍 1
j

Jan

10/06/2023, 12:54 PM
I think I saw something that the images are bundled into ios when the framework is build, but I right now I cannot find the source
maybe it was an issue of the compose-multiplatform github repo
I am really not sure if that answers your question and I haven't tried it myself yet, but that was something I stumbled across while doing some mini research
thank you color 1
n

Nikita Lipsky

10/06/2023, 2:12 PM
Common module resources are available from Compose only. So "without Moko and without CMP" is not a valid requirement -- both Moko and CMP resource deployment are handled by their Gradle plugins that have no sense without their APIs. That is because Kotlin Multiplatform does not handle deployment of resources from common module anyhow: so if you don't use Moko or CMP, resources won't be deployed to final iOS bundle at all (until you write your own Gradle plugin to handle this). On the other hand, if you use say CMP resource library, you may export resource loading function and use it form Swift. However if you need SwiftUI image you will need to convert byte array to image using SwiftUI API. Another possible solution is to use Compose Multiplatform UIKit interop, So an image will be shown by Compose but embedded into SwiftUI. Finally you may load a resource using iOS File API, however I would not recommend this, because resource placement is implementation details and may change in the future.
thank you color 1
m

mohamed rejeb

10/06/2023, 3:00 PM
For now I added CMP and I'm using CMP Resources to handle this, res string -> Resource -> ByteArray -> NSData -> UIImage, I think that we can have some APIs to make this easier in the future. Also I think having some public APIs for resources without CMP is better for projects with native ui, there's no need for the extra size added by Skiko.
… on the hand if you have native ui probably it is better to use native resources as well
m

mohamed rejeb

10/06/2023, 3:16 PM
Yes, it makes much sense to use native resources with native UI
5 Views