compose-multiplatform icon indicating copy to clipboard operation
compose-multiplatform copied to clipboard

Add SVG support for arbitrary data sources

Open mipastgt opened this issue 1 year ago • 2 comments

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.

mipastgt avatar Apr 16 '24 10:04 mipastgt

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.

terrakok avatar Apr 18 '24 13:04 terrakok

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
    )

gleb-skobinsky avatar May 20 '24 22:05 gleb-skobinsky

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

terrakok avatar Jun 21 '24 12:06 terrakok

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

terrakok avatar Jun 21 '24 12:06 terrakok

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

okushnikov avatar Aug 26 '24 13:08 okushnikov