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

Halil Ozercan

07/23/2020, 7:41 PM
I see that with dev15,
Transition
composable is deprecated in favor of
transition
which is highly similar but instead of receiving children as a trailing lambda, it provides a state that can be used by following composables in the same scope. The docs suggest that
toState
is the main control unit for transition state. Whenever it changes, animation will change the course to this new destination state whether the animation was running or not. However, I'm having trouble understanding how to reset the current animation all together. Let's say my initial configuration is to go from
A
to
B
. In the middle of this transition, Composable receives a new state, which means the animation needs to restart. Animation should go back to state
A
and again head for
B
. I could not find a way of simply resetting
initState
and
toState
at the same time. What is the recommendation for such behavior?
i

Ian Lake

07/23/2020, 7:50 PM
@Doris Liu
As I understand it, the system is physics based - you wouldn't jump cut back to A, you'd just change your final state and the system manages the transition between where you are and where you want to be
h

Halil Ozercan

07/23/2020, 7:56 PM
I feel like the whole animation API is designed around fluidity. As in
transitionDefinition
, there are no shortcuts between states. I wish there was an easy way to reset animation state for simple use cases.
d

Doris Liu

07/23/2020, 8:14 PM
Please correct me if I'm wrong: you would like to restart from A to B during an existing animation from A to B. There would inevitably be a big jump to reset everything, though
Could you elaborate on the specific use case? I'm curious what you are animating specifically. It's not hard to support such behavior, we just haven't found a use case to justify it. 😉
h

Halil Ozercan

07/23/2020, 8:39 PM
Yes I admit it's a rare case 🙂 In my situation, I need a quick rewind or forward seek animation for a video player. It's really similar to what Netlifx has. Youtube's double tap forward or rewind actually adds +10 seconds to the ongoing animation text if user double taps successively. Netflix restarts the +10 seconds animation. The latter is what I wanted to add to my player. I believe we can come up with many other use cases where animation is the result of an event stream whose publication period can be shorter than animation duration.
d

Doris Liu

07/24/2020, 7:08 PM
Thanks for sharing your use case. It is indeed a case that we have not considered for state transition. 😄 AnimatedValue series of animations are designed to cater event driven use cases, which supports imperative usage pattern via
snapTo
,
animateTo
and in some cases
fling
. I'll consider having a similar variant for transition.
BTW, your impression on the API being designed around fluidity is spot on. The goal is to make fluid animations the happy path, while providing lower level APIs for those who stray away from the happy path. 😛