Add SVG support for arbitrary data sources
The pull request https://github.com/JetBrains/compose-multiplatform/pull/4605 introduced support for SVG drawables for non android platforms but there still does not seem to be an equivalent, multiplatform variant of the method
public fun loadSvgPainter(inputStream: java.io.InputStream, density: androidx.compose.ui.unit.Density): androidx.compose.ui.graphics.painter.Painter
to create an SVG painter from an arbitrary data source like, e.g., a ByteArray. Currently the support seems to be limited to resources unless I missed something.
Yes, we plan to add a such method to the compose core in the future. I mean the method to create a painter from a svg's ByteArray.
I just found out that you can provide a ByteArray to the new multiplatform Coil AsyncImage and it will work fine.
coil3.compose.AsyncImage(
model = ImageRequest.Builder(LocalPlatformContext.current)
.data(byteArray)
.decoderFactory(SvgDecoder.Factory())
.build(),
modifier = modifier,
contentDescription = null
)
Back to the issue: we don't have a plan to support the SVG rendering on android. It requires to have additional runtime dependency for a SVG processing on the android. There are libraries support it already: coil or sketch or compose-imageloader
For non-android targets there will be a method to convert a bytearray to the painter in the compose.ui module in the future though
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.