Thread
#compose
    Robert Menke

    Robert Menke

    1 year ago
    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?
    @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]

    1 year ago
    In the next release of compose you can pass
    Color.Unspecified
    as a tint to
    Icon
    , and it won't tint the icon