I'm looking for an easy way to get a `androidx.com...
# compose-ios
s
I'm looking for an easy way to get a
androidx.compose.ui.graphics.painter.Painter
for my SVG & bitmap resource images. For JVM we have
loadXmlImageVector()
and
BitmapPainter
, which are not available for Compose for iOS. I have them in a folder, but I wouldn't mind (for now) to further use the
Assets.xcassets
as SwiftUI requires me to. I looked at https://github.com/Kotlin/kmm-production-sample/tree/compose-app which uses https://github.com/Skeptick/libres to do that, but this unfortunately requires CocoaPods, which I don't want in my project setup. What are other options to use SVG & Bitmaps for my Icons with Compose for iOS?
The only thing that comes to my mind is
Image.makeFromEncoded(nsData.toByteArray()).toComposeImageBitmap()
, but I would like to continue using SVGs for my icons.
Ok, as far as I can see also the official solution requires CocoaPods and the way to avoid this is not documented. Does somebody figured out how to do it and can provide an example? https://kotlinlang.slack.com/archives/C0346LWVBJ4/p1681737215033999?thread_ts=1681735276.820739&cid=C0346LWVBJ4
m
For Bitmaps you can just use the new (since 1.4.0)
Copy code
org.jetbrains.compose.resources.painterResource
which you can get via
Copy code
implementation(compose.components.resources)
and for SVG a modified version of
Copy code
androidx.compose.ui.res.SVGPainter and
androidx.compose.ui.graphics.vector.DrawCache
from the desktop implementation. It is actually quite simple because both desktop and iOS are based on Skia. I just had to modify the loader so that it can read from a ByteArray instead of a Java stream. You can read the raw ByteArray as a resource via the resource package mentioned above.
s
Thanks. Yes, I play around with that right now. I try to figure out what CocoaPods actually does in the mix and if I this can be done by a Gradle task.
a
you can use moko-resources without cocoapods
s
This is already compatible with Compose for iOS?
s
Nice, I will check that out 🙂 🙏
a
I had issues loading SVGs using
painterResource