I need something like a finish listener when using...
# compose
m
I need something like a finish listener when using Transition.AnimatedVisibility(), but I don't find any in the API. For example, how can I fade out a heart that has been faded in with previous transition?
d
In the spirit of making Transition declarative, we don't have a finish listener for it. But whether the animation has been finished can be derived from
Transition.currentState == Transition.targetState
. You could: 1) Use
MutableTransitionState
to create the Transition/AnimatedVisibility, and change the
MutableTransitionState#targetState
when
MutableTransitionState.isIdle
. or 2) Create a
snapshotFlow
of the
Transition.currentState
to get the event when the state changes. If you are only trying to fade in & out a heart repeatedly, a
repeatable
animation in an InfiniteTransition or Transition may be a better choice.
πŸ™ 2
βž• 1
m
Sounds pretty complicated πŸ™‚ πŸ˜…
πŸ˜… 1
d
Are you just trying to get the heart fade in and out repeatedly?
m
No, just making it fade in and stay for a second and fade out, something like an instagram animation that happens when the user double taps a picture.
d
m
Oh, that's nice. Thank 😊you @Doris Liu πŸ™
πŸ‘ 1