Open NatashaIJ opened 7 months ago
The svg decoder should already take into account the intrinsic size. Can you try setting useViewBoundsAsIntrinsicSize = false
and see if that fixes your issue? Does it work properly if you use AsyncImage
instead of rememberAsyncImagePainter
?
Can you include sample code that reproduces the issue? It sounds like you might be using a specific combination of size modifiers.
If the ask is to multiply an SVG image's intrinsic width/height px
to match its density similar to https://github.com/coil-kt/coil/issues/2048 then we could potentially add a new constructor param. Though, my understanding of the SVG specification was that values represented in px
units shouldn't be scaled to a device's density. This change would add different behaviour from the specification.
Sample code: CoilImages.zip
Description: In a Jetpack Compose project utilizing Coil (version 2.4.0), SVG images loaded from URLs fail to retain their intrinsic dimensions, scaling up to the maximum size set with .sizeIn(maxWidth = 16.dp, maxHeight = 16.dp). This issue does not occur with SVGs loaded from drawable resources, which correctly maintain their intrinsic sizes. To ensure accurate sizing, Size.ORIGINAL is utilized in the image request, which leads to another problem: the images become blurry due to scaling from pixel-based sizes to dp in the UI.
Steps to Reproduce:
Expected Behavior:
Additional Context: A custom SvgDecoder was introduced to tackle the blurriness, altering the getDstSize function to translate SVG dimensions into dp for UI consistency. While this resolved the blurriness, modifying library components is risky, potentially leading to future compatibility issues. Ideally, default support for this scenario in the SVGDecoder would avoid the need for custom implementations.
Version: Coil version: 2.4.0 The problem has been noted on various API levels and Android devices.
Related Bug and Discussions:
Note: In my view, such intrinsic size handling should be natively supported by Coil's SVGDecoder to avoid the need for custom implementations that may introduce future maintenance challenges.