Toan Nguyen
08/01/2023, 7:29 AManimateScrollToPage
in LaunchedEffect
, the screen will show 1/2 ui pager when job is working. But when i add job animateScrollToPage
in coroutineScope
, it’ll work correct. This is bug LauncherEffect
in compose? So somebody can explain me the reason?Yann Badoual
08/01/2023, 7:50 AMpagerState.currentPage
is changing before the animation is completed. It would cause the LaunchedEffect
block to be cancelled (and thus the animation)
You can also use a snapshotFlow on currentPage to observe and scroll (removing the key from LaunchedEffect would fix the bug + avoid unnecessary recomposition)Toan Nguyen
08/01/2023, 8:03 AMxoangon
08/01/2023, 8:06 AMrememberCoroutineScope
. The reason is that LaunchedEffect
is only triggered when you enter the composition phase, but a remembered CoroutineScope could be used to trigger async events at any other point outside of composition.
This article by @Jorge Castillo explains it pretty neatly --> https://newsletter.jorgecastillo.dev/p/jetpack-compose-effect-handlersxoangon
08/01/2023, 8:09 AMToan Nguyen
08/01/2023, 8:11 AM