Luke
02/21/2023, 5:21 PMrook
02/21/2023, 5:39 PMTargetBasedAnimation
, you can calculate whether the animation is over in a LaunchedEffect
and then call-back to a completion lambda with something like this:
val startTime = withFrameNanos { it }
do {
val playTime = withFrameNanos { it } - startTime
animatedValue.value = animation.getValueFromNanos(playTime)
if (animation.isFinishedFromNanos(playTime)) {
onCompleted(runningState)
break
}
} while (true)
Doris Liu
02/22/2023, 5:30 PMTransition
target states? If so, you could consider creating a MutableTransitionState
and using it in updateTransition. This way you could update `MutableTransitionState`'s targetState
whenever the transition finishes.
val mutableTransitionState = remember { MutableTransitionState(initialState) }
updateTransition(mutableTransitionState, label = "...")
LaunchedEffect(mutableTransitionState) {
snapshotFlow {
mutableTransitionState.currentState == mutableTransitionState.targetState
}.collect { finished ->
if (finished) {
// change target to the next transition state
mutableTransitionState.targetState = nextState
}
}
}
rook
02/22/2023, 6:43 PMLuke
02/22/2023, 7:43 PM