Is there any practical way to load SVG files on Compose/iOS at the moment? I can see the `Image`/`Im...
d
Is there any practical way to load SVG files on Compose/iOS at the moment? I can see the `Image`/`ImageVector`/`vectorPainter` API set is present - any existing code to get SVG format loaded into that?
m
iOS is a Skia target so
SVGPainter(SVGDOM(Data.makeFromBytes(bytearray)), density)
should work
s
Wait - so with this, we can load SVGs multiplatform?
That’s what I’ve been waiting for with compose-web
m
Looks like it, the jsMain depends on skiaMain for that library
androidMain doesnt, but it has its own svg loading utils
d
Just confirming here that borrowing the Skia API-based SVG rendering code from the link above did easily lead to rendering SVG's on both iOS and Desktop 🎉 ...while Desktop already has its own dedicated convenience methods for SVG rendering; using this Skia code just happened to result in a new shared-code function between iOS/Desktop 👍 (Hopefully in mid-future JB will extend some of Desktop's conveniences to iOS)
s
I've been using this plugin to convert SVG files to ImageVector https://plugins.jetbrains.com/plugin/18619-svg-to-compose
d
That's interesting @Simon E, I wasn't aware of that plugin, thanks for sharing - would surely result in better runtime performance at the cost of some extra maintenance. Is the plugin one-shot manual generation only, or can you integrate it into a codegen/build process?
s
It's just an intellij plugin, so it adds a new GUI option to select a folder with svg files and generate ImageVector objects from these. However it wraps this project https://github.com/DevSrSouza/svg-to-compose so I suppose you might be able to more with this.
1774 Views