A transparent to white `Brush.verticalGradient` in...
# compose
a
A transparent to white
Brush.verticalGradient
in a white
Box
renders gray with
drawWithCache
. A bug? Code in 🧵
Copy code
Box(
  Modifier
    .size(50.dp, 50.dp)
    .background(Color.White)
    .drawWithCache {
      onDrawWithContent {
        drawContent()
        drawRect(
          Brush.verticalGradient(
            .5f to Color.Transparent,
            1F to Color.White
          )
        )
      }
    }
)
z
I'm not at a computer atm but i think transparent might set the other color channels to zero, and so it ends up interpolating between transparent black and opaque white which gives you the gray?
You could try doing
Color.White.copy(alpha=0f)
instead of
Transparent
🙌 1
a
That's fantastic, Zach. Thank you. Should I report that as a bug? The gray gradient seems rather strange seeing as
Color.Transparent
was set.
z
I don't think it's worth filing a bug, I think you just have to be careful when lerping colors that if you only want to lerp the alpha channel, you make sure that's the only channel that's different.
👍 1