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

Maik

10/27/2020, 1:23 PM
Is there any obvious reason why the modifier
drawOpacity
enables clipping in addition to the alpha value. From my point of view this seems to be a mistake, because it is not 100% clear from the modifier name or its description.
Copy code
/**
 * Draw content with modified opacity (alpha) that may be less than 1.
 *
 * Example usage:
 * @sample androidx.compose.ui.samples.OpacitySample
 *
 * @param opacity the fraction of children's alpha value.
 */
@Stable
fun Modifier.drawOpacity(
    @FloatRange(from = 0.0, to = 1.0) opacity: Float
) = drawLayer(alpha = opacity, clip = true)
j

jim

10/27/2020, 1:58 PM
Hmm, that does seem not ideal. b/152810850 explicitly states that clipping should be
true
for opacity, but doesn't elaborate, I wonder if this was for performance reasons. cc @George Mount
a

Adam Powell

10/27/2020, 3:44 PM
I imagine this is probably because we end up rendering contents into an offscreen buffer in order to draw with alpha and the size of that buffer needs to be bounded, hence the clip
n

Nader Jawad

10/27/2020, 6:15 PM
Yes it's precisely that. Opacity introduces a layer to render the content of the composable into it then draws that layer with the alpha. The layer itself is bounded and hence clips
2 Views