How to draw images/icons from .xml files in multip...
# multiplatform
j
How to draw images/icons from .xml files in multiplatform? What dependencies do I need?
z
There's a first-party (experimental) solution, with this dependency which is added by default in the multiplatform templates (like this one):
Copy code
@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
implementation(compose.components.resources)
Then you just call the
painterResource
method and pass in the path of the image to draw, as seen here. --- Another option is moko-resources which can work with SVG images.
thank you color 1
🙌 1
j
Nice! Is there a way to follow the development of this first-party solution for images in multiplatform? First-party, meaning that JetBrains is developing this? Do you think this supports all platforms? Especially iOS?
z
The template linked above is for Android and iOS, so yes it does work on iOS. There's unfortunately no proper docs for it yet (again, it's still experimental), but we're working on creating documentation for it!
j
Nice
s
@zsmb Would this solution also support KMP solutions that don't use multiplatform Compose, that stick with the pure native UI implementations?
z
This is specific to using resources in Compose. If you're building native UI then using the respective resource systems of each platform is the way to go.
thank you color 1
j
I guess
AnimatedVisibility
is a nice to have based from the example?
How can I import this?
Add this to commonMain? @OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class) implementation(compose.components.resources)
..yep
Now we are using this in production =)))