Mohamed Ibrahim
08/17/2021, 8:04 PMColton Idle
08/17/2021, 8:12 PMMohamed Ibrahim
08/17/2021, 8:23 PMMohamed Ibrahim
08/17/2021, 8:23 PMflow {
(0..target).forEach {
delay(interval)
emit(it)
}
}.onEach {
animateFloat.animateTo(
targetValue = (it.toFloat() / target) * 360f,
animationSpec = tween(durationMillis = 1000, easing = FastOutSlowInEasing)
)
}.launchIn(scope = scope)
----------------Mohamed Ibrahim
08/17/2021, 8:24 PMLaunchedEffect(key1 = animateFloat) {
flow {
(0..target).forEach {
delay(interval)
emit(it)
}
}.collect {
animateFloat.animateTo(
targetValue = (it.toFloat() / target) * 360f,
animationSpec = tween(durationMillis = 1000, easing = FastOutSlowInEasing)
)
}
}
I could see that the way I launch Flow is the difference here, but why LaunchedEffect worked and the later didn’t.Doris Liu
08/17/2021, 11:22 PMLaunchedEffect
changes. When it does, the previous job will be canceled. So you won't be seeing multiple flows competing to emit new target for the animation.Mohamed Ibrahim
08/18/2021, 12:48 PM