https://kotlinlang.org logo
#compose
Title
# compose
r

Robert Menke

11/03/2020, 9:17 PM
So in order to avoid applying a tint to an
Icon
I’m using the below. Is there anything in the current compose lib that’s equivalent?
Copy code
@Composable
fun ColorIcon(asset: VectorAsset, modifier: Modifier = Modifier) {
    val painter = rememberVectorPainter(asset = asset)
    Box(modifier.defaultSizeFor(painter).paint(painter))
}

private fun Modifier.defaultSizeFor(painter: Painter) =
    this.then(
        if (painter.intrinsicSize == Size.Unspecified || painter.intrinsicSize.isInfinite()) {
            DefaultIconSizeModifier
        } else {
            Modifier
        }
    )

private fun Size.isInfinite() = width.isInfinite() && height.isInfinite()

// Default icon size, for icons with no intrinsic size information
private val DefaultIconSizeModifier = Modifier.preferredSize(24.dp)
l

Louis Pullen-Freilich [G]

11/03/2020, 10:21 PM
In the next release of compose you can pass
Color.Unspecified
as a tint to
Icon
, and it won't tint the icon
👏 1
5 Views