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

Se7eN

10/20/2020, 4:04 PM
Any ideas on how to pause and resume a transition? I have the following transition:
Copy code
transitionDefinition<StoryState>{
    state(StoryState.START) {
        this[progress] = 0f
    }

    state(StoryState.END) {
        this[progress] = 1f
    }

    transition(StoryState.START to StoryState.END) {
        progress using tween(5000, delayMillis = 500, easing = LinearEasing)
    }
}
I'd like to pause and resume the transition on a certain event. I guess we can't do that so what can I do?
y

Yann Badoual

10/20/2020, 4:38 PM
Never tried, but maybe you can do something with the clock passed building the transition
👍 1
d

Doris Liu

10/20/2020, 9:36 PM
AnimationClock
is probably the only way to achieve that, since
transition
composable isn't designed to be used imperatively. We may provide a lower set of APIs support imperative use of
TransitionAnimation
some time in the future. But for now, I'd recommend using
animatedFloat
(aka the imperative API for single value animation) for this use case. 🙂
👍 1
s

Se7eN

10/21/2020, 11:52 AM
Thanks for the help! I just saw
ManualAnimationClock
I'll try using it
So I'm creating a custom animation clock from
BaseAnimationClock
but it looks like
dispatchTime
is internal. Am I doing something wrong? @Doris Liu
d

Doris Liu

10/21/2020, 6:04 PM
I'd use a
ManualAnimationClock
for the dispatching - when you change the
clockTimeMillis
(conditionally based on whether you need to pause the animation) ,
ManualAnimationClock
will automatically dispatch the new time you set to the animations subscribed to it. 🙂 This does require some wire-up for your
ManualAnimationClock
to observe the time change during a normal run.
s

Se7eN

10/21/2020, 6:11 PM
Okay I was trying to add the pause and resume logic to the custom clock class by inheriting but sure I'll do it another way with
ManualAnimationClock
. Thanks 🙂
d

Doris Liu

10/21/2020, 6:16 PM
👍
4 Views