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
Doris Liu
08/21/2021, 5:32 PM
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
Mehdi Haghgoo
08/21/2021, 8:23 PM
Sounds pretty complicated 🙂 😅
😅 1
d
Doris Liu
08/21/2021, 8:37 PM
Are you just trying to get the heart fade in and out repeatedly?
m
Mehdi Haghgoo
08/21/2021, 8:49 PM
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.