Theres a recommendation to "delay" the read of a value, for example `Modifier.graphicsLayer { alpha ...
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.