Alexandru Hadăr
06/13/2023, 2:56 PMdrawRect
generate the same gradient effect as Box.background(gradient)
?
I'm trying to replicate the bottom fading effect at the top as well.
However, at the top, the white color persists across the whole gradient.
The code is in the 🧵Alexandru Hadăr
06/13/2023, 2:57 PMdrawWithCache
and `drawRect`:
val gradientBrush = Brush.verticalGradient(
0f to gradientStartColor,
1f to Color.Transparent,
)
onDrawWithContent {
drawContent()
drawRect(
brush = gradientBrush,
topLeft = Offset.Zero,
size = Size(width = size.width, height = 60.dp.toPx()),
)
Alexandru Hadăr
06/13/2023, 2:57 PMBox(
modifier = Modifier
.fillMaxWidth()
.height(60.dp)
.background(
brush = Brush.verticalGradient(
0f to Color.Transparent,
1f to gradientStartColor,
)
)
.align(Alignment.BottomCenter)
.zIndex(1f)
)
Rikin Marfatia
06/13/2023, 8:44 PMRikin Marfatia
06/13/2023, 8:45 PMstartY
and endY
params in your Brush.verticalGradient
Rikin Marfatia
06/13/2023, 8:46 PMbrush = Brush.verticalGradient(
0f to gradientStartColor,
1f to Color.Transparent,
startY = 0f,
endY = 60.dp.toPx()
),
Alexandru Hadăr
06/14/2023, 12:00 PMAlexandru Hadăr
06/14/2023, 12:00 PMRikin Marfatia
06/14/2023, 3:54 PM