Hi all ! Sorry for this long example just in order...
# compose
l
Hi all ! Sorry for this long example just in order to explain my main trouble : • I've drawn a checker board with some coins • We can drag a coin to an empty cell • If trying to drag a coin on another coin, then there should be a back animation. Unfortunately, the back animation is not thrown and the coin goes back immediately
I'm using android jetpack compose alpha11. For the animation, I've tried to set the final state manually
Copy code
goBackState.targetState = GoingBackStates.FINAL
(line 178)
Also I'm forbidden to write this
Copy code
goBackState.currentState = GoingBackStates.INITIAL
Otherwise : is a transition object cheap or expensive ? Because that way I could simply use a function to map each cell to a transition if it has a coin. And my code could be cleaner and more readable.
d
You can only change the
targetState
(i.e. not the
currentState
) of a Transition/MutableTransitionState. If you need to change both the starting point and ending point of a transition, you could create a new
MutableTransitionState
like the second sample on this API: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/package-summary#updatetransition_1 That would recreate the Transition animation with the new initial/target states specified in the new
MutableTransitionState
. Though that would mean that all the current values/velocities of the animation will be lost, and you may therefore see a visual jump.
👍 1
Creating a bunch of
Transition
s is not super expensive. I agree with you that each cell (in the snippet above) should have independent animation/transition states. I'd suggest having an
Animatable<Offset>
for each cell to animate their position as needed, independently.
👍 1
l
Thank you very much 🙂 So I'm going for the array of Transition 🙂
Strange issue : Looking at https://developer.android.com/reference/kotlin/androidx/compose/animation/core/Animatable, Animatable is a class that takes two parameters. But in my Android Studio Canary, I get an error saying that Animatable do not take parameter. I am using compose 1.0.0-alpha11
d
Animatable
has a few overloaded factory methods. Also make sure you import the right one. There's also a Drawable class with the same name. 😅
l
Thank you. I check my imports 🙂
I did not read the documentation correctly: I'm just using
Copy code
Animatable(Offset(0f, 0f), Offset.VectorConverter)
and that's fine.