https://kotlinlang.org logo
#compose
Title
# compose
b

bruno.aybar

02/21/2021, 8:54 PM
Hello. On the old Transition API,
transition
s had
onStateChangeFinished
callback. Does anyone know if there's a similar callback on the new API?
I inspected
Transition
code and seems like that is not supported. I wonder if that could be done here 🤔 or maybe having a callback for that is not a good idea?
z

Zach Klippenstein (he/him) [MOD]

02/21/2021, 11:35 PM
Most of the animation apis have an animation ended event handler that gets a reason
b

bruno.aybar

02/21/2021, 11:56 PM
The new animation (
animate*asState(...)
) apis have
finishedListener
parameters, yes. However, the transition apis (
updateTransition
,
transition.animate*(..)
) do not. So, when handling transitions, I'm not sure if there's a way to know "all the animations for this transition have ended"
d

Doris Liu

02/22/2021, 6:58 PM
The new transition has a
currentState
that can be observed.
currentState == targetState
signals that the transition for all animations has finished. 🙂
b

bruno.aybar

02/23/2021, 12:28 AM
Thanks @Doris Liu! At the beginning it was a bit complicated to wrap my head around transition changes as State updates, but makes sense! I got it working, thank you 🙏
d

Doris Liu

02/23/2021, 12:38 AM
Glad it worked for you! 🙂 Expressing the finished event as a state change makes sequencing transition states a bit nicer, like in this example: https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]/androidx/compose/animation/demos/DoubleTapToLikeDemo.kt;l=74
b

bruno.aybar

02/23/2021, 12:42 AM
wooow... yes, that indeed looks pretty. And here I was writing a queue of states to handle sequencing transition states 🙃
once I'm done with my changes, I would really appreciate your feedback, if possible 😅
d

Doris Liu

02/23/2021, 12:44 AM
once I'm done with my changes, I would really appreciate your feedback, if possible
Sure thing! I'm happy to take a look! 🙂