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)?