Theres a recommendation to "delay" the read of a v...
# compose
z
Theres a recommendation to "delay" the read of a value, for example
Modifier.graphicsLayer { alpha = state.value }
in order to reduce the recomposition scope. I feel like that doesnt matter when using a Modifier? Example in 🧵!
Copy code
private fun Modifier.visibility(
    visible: Boolean
): Modifier {
    return composed {
        val alphaState = animateFloatAsState(
            target = if (visible) 1f else 0f
        )

        graphicsLayer {
            alpha = alphaState.value
        }
    }
}
I might as well do this?
Copy code
val alphaState by animateFloatAsState(
    target = if (visible) 1f else 0f
)
Because the recomposition scope doesnt change if I "delay" the read. Am I understanding that right?
For clarity.. I mean doing the
by
thing inside the Modifier.composed block 🙂
r
When using
by
, the
alphaState
will still be read where it's used, so in this case inside
graphicsLayer
So in this case it doesn't matter, you're "still deferring the read", so all good 👍
So you're skipping recomposition here
a
Yeah, using
=
and
by
is completely the same in terms of recomposition scope.