Se7eN
10/13/2020, 4:50 PMval emojiState = remember { mutableStateOf(EmojiState.HIDDEN) }
val definition = transitionDefinition<EmojiState> {
state(EmojiState.HIDDEN) {
this[emojiSize] = 0.dp
}
state(EmojiState.START) {
this[emojiSize] = 20.dp
}
state(EmojiState.END) {
this[emojiSize] = 50.dp
}
transition(fromState = EmojiState.START, toState = EmojiState.END) {
interruptionHandling = InterruptionHandling.SNAP_TO_END
emojiSize using tween(3000, easing = FastOutSlowInEasing)
}
}
val transitionState = transition(
definition = createEmojiTransition(),
initState = emojiState.value,
toState = if (emojiState.value == EmojiState.START) EmojiState.END else EmojiState.HIDDEN,
onStateChangeFinished = {
emojiState.value = it
}
)
When I change emojiState
to HIDDEN
while the transition from START
to END
is going on, it looks like the transition isn't interrupted and still going on in the background.
For example, I change the transition to HIDDEN
1000 millis after starting the START
to END
transition, then after 2000 millis the onStateChangeFinished
is run and it sets my state back to END
. Is there some way I can interrupt the transition and prevent onStateChangeFinished
to be called for interrupted transitions. Or maybe my logic is at fault here?Se7eN
10/13/2020, 5:49 PMAfzal Najam
10/13/2020, 6:49 PMSe7eN
10/13/2020, 7:06 PMbruno.aybar
10/14/2020, 2:26 AMSe7eN
10/14/2020, 6:18 AMDoris Liu
10/20/2020, 9:19 PMinitState
gets changed (or when TransitionDefinition
is re-created), the animation starts over. That's probably why the animation isn't interrupted. Both seem to be happening here. Unless you need the transition to start an animation as soon as it gets composed for the first time, I'd recommend leaving it undefined. You might also want to remember the TransitionDefinition
if it's not created at the file level. 🙂Se7eN
10/22/2020, 2:21 PMHIDDEN
state. But I didn't get what you mean by leaving it undefined. I was starting from HIDDEN
so the transition won't go off when it first composes.
Also, thanks for the remember tip I wasn't doing that 🙂Doris Liu
10/23/2020, 11:49 PMtoState
when it is first composed. Therefore the default behavior when you don't define initState
is that the transition doesn't go off when it's first composed. 🙂Se7eN
10/25/2020, 6:49 AM