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

adjpd

09/29/2021, 9:00 PM
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

Zach Klippenstein (he/him) [MOD]

09/30/2021, 5:48 AM
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

adjpd

09/30/2021, 11:45 AM
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

Zach Klippenstein (he/him) [MOD]

09/30/2021, 4:33 PM
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