Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b0af159d authored by Olivier St-Onge's avatar Olivier St-Onge Committed by Android (Google) Code Review
Browse files

Merge "Read the animated color value in the drawing phase for icons" into main

parents 5188ceb9 1c0af7a1
Loading
Loading
Loading
Loading
+16 −11
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.draw.drawWithCache
import androidx.compose.ui.draw.drawWithContent
import androidx.compose.ui.draw.paint
import androidx.compose.ui.geometry.Offset
@@ -70,6 +71,7 @@ import androidx.compose.ui.graphics.DefaultAlpha
import androidx.compose.ui.graphics.TransformOrigin
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.graphics.layer.drawLayer
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.layout.Layout
@@ -293,7 +295,7 @@ fun SmallTileContent(
            NonClippedImage(
                painter = painter,
                contentDescription = icon.contentDescription?.load(),
                colorFilter = ColorFilter.tint(color = animatedColor),
                tint = { animatedColor },
                modifier = iconModifier,
                contentScale = ContentScale.Crop,
            )
@@ -306,7 +308,7 @@ fun SmallTileContent(
            )
        }
    } else {
        Icon(icon = icon, tint = animatedColor, modifier = iconModifier)
        Icon(icon = icon, tint = { animatedColor }, modifier = iconModifier)
    }
}

@@ -409,7 +411,6 @@ object CommonTileDefaults {
    val LargeTileIconSize = 28.dp
    val SideIconWidth = 32.dp
    val SideIconHeight = 20.dp
    val ChevronSize = 14.dp
    val ToggleTargetSize = 56.dp
    val TileHeight = 72.dp
    val TileStartPadding = 8.dp
@@ -438,7 +439,7 @@ private fun NonClippedImage(
    alignment: Alignment = Alignment.Center,
    contentScale: ContentScale = ContentScale.Fit,
    alpha: Float = DefaultAlpha,
    colorFilter: ColorFilter,
    tint: ColorProducer,
) {
    val semantics =
        if (contentDescription != null) {
@@ -455,13 +456,17 @@ private fun NonClippedImage(
    Layout(
        modifier
            .then(semantics)
            .paint(
                painter,
                alignment = alignment,
                contentScale = contentScale,
                alpha = alpha,
                colorFilter = colorFilter,
            )
            .drawWithCache {
                // Applying the color filter directly on the layer since it's an animated value.
                // This is taken from the Material3 Icon implementation
                val layer = obtainGraphicsLayer()
                layer.apply {
                    record { drawContent() }
                    this@apply.colorFilter = ColorFilter.tint(tint())
                }
                onDrawWithContent { drawLayer(graphicsLayer = layer) }
            }
            .paint(painter, alignment = alignment, contentScale = contentScale, alpha = alpha)
    ) { _, constraints ->
        layout(constraints.minWidth, constraints.minHeight) {}
    }