https://kotlinlang.org logo
#compose
Title
# compose
t

Tim Malseed

03/21/2023, 12:04 AM
I have a composable ‘screen’, that uses
LaunchedEffect
to perform one-off navigation events, based on state. So, for example, if the current
viewState
is
Unauthorized
, I might use a
LaunchedEffect
to call
navigateToLoginScreen()
But, let’s say there are two of these launched effects, with two possible navigation destinations. I’ve noticed an issue where, if the
viewState
updates and triggers a navigation event - the
viewState
can again update before that navigation transition is complete - triggering yet another navigation event. This means my navigation can end up in an unexpected state. Is there a way to ensure a LaunchedEffect is cancelled before the composition leaves the tree (like, during a navigation transition)?
b

Ben Trengrove [G]

03/21/2023, 1:08 AM
i

Ian Lake

03/21/2023, 3:19 AM
FWIW, probably a better question for #compose-android going forward
But yep, checking for
RESUMED
is enough, see the previous time we discussed this: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1677626180373409?thread_ts=1677626180.373409&cid=CJLTWPH7S
t

Tim Malseed

03/21/2023, 3:19 AM
Ohhh I thought compose and compose-android were merged
i

Ian Lake

03/21/2023, 3:22 AM
Just the opposite, #compose-android is the new home for Android only stuff: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1678882852468139
t

Tim Malseed

03/21/2023, 3:22 AM
No worries, thanks 🙂
Thanks all. I tried this approach (only navigate if the initiating back stack entry is resumed). It solves one problem, but introduces another! I’ve asked over at #compose-android. It feels rather complicated 😞 https://kotlinlang.slack.com/archives/C04TPPEQKEJ/p1679372439660899
28 Views