Maik

    Maik

    1 year ago
    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.
    /**
     * 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)
    jim

    jim

    1 year ago
    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
    Adam Powell

    Adam Powell

    1 year ago
    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
    Nader Jawad

    Nader Jawad

    1 year ago
    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