Status Update
Comments
nj...@google.com <nj...@google.com> #2
As part of the move away from data classes as part of public API, the copy method was removed. Copy never directly allowed for copy and replacement of the entire vector graphics API originally.
For this particular use case, if the intent is to change how large the Vector asset is to be drawn, this should be a parameter configured as part of the composable it was configured with. Historically this is done by configuring a size modifier as you have shown in your example, however, Icon is a material specific API optimized for the convenient use case of just drawing an ImageVector with its intrinsic size. For this particular use case consider usage of the Image composable instead. This allows for the size of the composable to be configured dynamically and for the vector to scale accordingly allowing for configuration of the positioning through the Alignment API as well as the scaling algorithm via ContentScale.
You should be able to accomplish this goal by leveraging the Image composable with the painterResource API instead with the following:
Image(
painter = painterResource(R.drawable.ic_icon),
modifier = Modifier.size(100.dp),
contentDescription = "my icon"
)
Image is a superset of the functionality that the Icon composable provides and also allows for additional ColorFilter usages by configuring the optional colorFilter
parameter (ex. colorFilter = ColorFilter.tint(Color.Red)
)
tr...@gmail.com <tr...@gmail.com> #3
lp...@google.com <lp...@google.com> #4
Thanks for the request! Using Modifier.size
with Icon
should also work for simpler cases when you do not need to provide a custom ColorFilter
or similar, so we should definitely support this functionality in Icon
too. Re-opening this bug to track.
lp...@google.com <lp...@google.com> #5
This has now been fixed, so in the next release of Compose writing just:
Icon(vectorResource(R.drawable.ic_icon), modifier = Modifier.size(100.dp))
should make the icon 100x100dp, and draw to fit the space.
Description
Android Studio Build: Arctic Fix 2020.3.1 Canary 5
Alpha 11 lost the ability for us to change the default size of an icon loaded with vectorResource. In Alpha 10 I could do this by using:
Icon(vectorResource(R.drawable.ic_icon).copy(defaultWidth = 100.dp, defaultHeight = 100.dp))
This no longer works in Alpha 11. I did sort of find a way around this using the following:
Icon(vectorResource(R.drawable.ic_icon), modifier = Modifier.size(100.dp).scale(4f))
But this causes the vector to become pixelated. I thought the whole point of using vector resources is to be able to easily scale to any size and avoid pixelation?