This helped me fix the issue:
Box(
modifier = Modifier
.fillMaxWidth(widthPercentage)
.fillMaxHeight()
// should not use .background() here
// use graphicsLayer as a work around to enable alpha compositing
.graphicsLayer {
alpha = 0.99f
}
.drawWithContent {
drawRect(
brush = Brush.horizontalGradient(
colors = listOf(
Color.Red,
Color.Blue,
)
)
)
drawRect(
brush = Brush.verticalGradient(
colors = listOf(
Color.Black.copy(alpha = 0.6f), // the color doesn't matter
Color.Transparent,
),
),
blendMode = BlendMode.DstIn,
)
}
)