Is there any obvious reason why the modifier `draw...
# compose
m
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
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
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
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