Is there any APIs for being notified about an anim...
# compose
a
Is there any APIs for being notified about an animation being finished in
AnimatedVisibility
? (like
onFinishedListener
)
m
It's not a listener, but you can react to transition state. Your layout would be recomposed and you can do something then - I'm not sure what kind of action you want to perform, but maybe this will help you:
Copy code
// yourContent is not visible by default
val transitionState = remember { MutableTransitionState(false) }

// trigger it to be visible at some point
transitionState.targetState = isVisible

AnimatedVisibility(transitionState) {
    YourContent()
}

if (transitionState.isIdle && transitionState.targetState) {
    // here your content is visible and animation is idle
}
❤️ 1
You can also play with
snapshotFlow
to convert this state to
Flow
and invoke some action on state change: https://developer.android.com/jetpack/compose/side-effects#snapshotFlow
Copy code
LaunchedEffect(key1 = transitionState) {
    snapshotFlow { transitionState.isIdle && transitionState.targetState }
        .filter { it == true }
        .collect {
            // some action
        }
}
a
I did not know about the TransitionState. It might help. Thanks.
👍 1