bryankeltonadams
07/12/2024, 7:17 PMval navigateToItemPickerList by viewModel.navigateToItemPickerList.collectAsStateWithLifecycle()
(this is passed into the ui further) onClickAddItem = viewModel::onClickAddItem,
LaunchedEffect(navigateToItemPickerList) {
if (navigateToItemPickerList) {
viewModel.resetNavigateToItemPickerList()
onClickAddItem(locationSelectorUiState.selectedLocation)
}
}
So that way I can perform all the validation stuff, and update the ui for the elements that failed validation, or if everything passes I can set the flag to navigate, and then this LaunchedEffect will trigger?
Is there anything wrong with how I'm doing this, it's a pattern I follow in a lot of places and seems to work just fine, but wondering if there's a better way to do this sort of thing?Viktor Nyblom
07/13/2024, 7:27 AM// HomeScreenViewModel
protected val eventsChannel = Channel<E>()
val events = eventsChannel.receiveAsFlow() // expose as flow
// HomeScreen
LaunchedEffect(Unit) {
screenmodel.events.collect {
log.d { "Event: $it" }
when (it) {
is Event.LoggedOut -> {
navigator.replace(LoginScreen())
}
is Event.OnboardingComplete -> navigator.push(IntroScreen())
}
}
}
}
Viktor Nyblom
07/13/2024, 7:28 AMsealed interface Event {
data class OnboardingComplete(val user: String) : Event
data object LoggedOut : Event
}
Stylianos Gakis
07/13/2024, 9:06 AMViktor Nyblom
07/13/2024, 9:24 AMuiState.paymentResult?.let {
val currentOnPaymentMade by rememberUpdatedState(onPaymentMade)
LaunchedEffect(uiState) {
// Tell the caller composable that the payment was made.
// the parent composable will act accordingly.
currentOnPaymentMade(
uiState.paymentResult.paymentModel,
uiState.paymentResult.isPaymentSuccessful
)
}
}
I need to sit with this a bit to make up my mind about it. I understand the reasoning around keeping everything in the UI state, but having to clear transient state (as mentioned as a Note at the end of the article) is also very annoying. Bugs from not clearing transient state is exactly what made me start using Channels instead. =)Stylianos Gakis
07/13/2024, 9:28 AMbryankeltonadams
07/13/2024, 9:46 PM