abbic
11/14/2022, 2:55 PMLaunchedEffect(key1 = event) {
when (event) {
ManualPaymentEvent.LoadingError -> {
scaffoldState.snackbarHostState.showSnackbar(
message = snackbarMessage,
actionLabel = snackbarAction,
duration = SnackbarDuration.Indefinite
)
viewModel.onSnackBarDismissClicked()
}
ManualPaymentEvent.NavigateBack ->
navigateUp()
is ManualPaymentEvent.NavigateWithCards ->
navigateToSelectCard(event.amount, event.cards)
is ManualPaymentEvent.NavigateWithoutCards ->
navigateToAddCard(event.amount)
null -> Unit
}
viewModel.eventConsumed()
}
viewModel.eventConsumed()
sets the event to null again, to show it has been consumed. onSnackbarDismissClicked
updates the uiState with uiState = uiState.copy(event = ManualPaymentEvent.NavigateBack)
. the intent here is that the NavigateBack event triggers the navigateUp()
function but this never happens.
The issue appears to be that the event is first set to NavigateBack. then before this LaunchedEvent can trigger, the event is first set to null, and this NavigateBack event is ignored.
What should i be doing? would this be resolved if i was holding my state in a Flow of some kind?abbic
11/14/2022, 3:00 PM