Status Update
Comments
po...@google.com <po...@google.com> #2
Chuck, from the description here it looks to me that in the first snippet we reuse the same lambda for graphicsLayer
because the read of dx is not captured. I believe this is WAI unfortunately, but passing it to you to have a look.
ol...@gmail.com <ol...@gmail.com> #3
I had a response from Andrey Kulikov and it seems that it's the intended behavior according to his response:
Shapes were designed to be immutable, meaning the constructed Shape instance should always be returning the same Outline for the same input size.
In your case your Shape is dynamic as it uses the dynamic property inside the outline creation lambda.
We don’t currently handle that (and didn’t have plan to make it work yet). the second snippet is correct as you can use the dynamic MutableState based property inside the layer builder lambda, when the state changes this block is reexecuted, and during the execution you recreate a new immutable Shape
ch...@google.com <ch...@google.com> #4
Lambdas are reused based on the values they capture. They are conditionally reused if they capture stable values based on the value of the stable values.
The first snippet, the lambda is reused because it captures dx
, a State<T>
which is considered stable. The lambda is not replaced when dx
changes because the container itself did not change (that is, it is the same State<T>
, just with a different value). Also, since dx
is not read, it doesn't trigger a recomposition so the animation of dx
is ignored by composition.
The second snippet the value of animDx
, which is a primitive and is considered stable, but now a new lambda is produced whenever animDx
is changed. Since dx
is now read during composition, changes to dx
will cause TicketWaveComposable
to recompose whenever dx
changes producing a new lambda for GenericShape
triggering normal recomposition updates to occur and eventually scheduling a new draw with the new shape.
I passing this to Andrey as the runtime is working as intended. We should consider observing reads performed by the shape
it would be nice to not have to involve composition for this kind of animation.
Description
Hello there there! When playing with animation and shapes I've been running in a weird behavior. If I run the code below, nothing happens the animation is not trigged. The animated float value is passed directly to the GenericShape lambda:
But If I modify the graphicsLayer{} like this and passing by an intermediate variable, the animation is working fine:
Android Studio:
Jetpack Compose: 1.0.0-beta04