Lucien Guimaraes
07/16/2021, 4:12 PMLucien Guimaraes
07/16/2021, 4:12 PMsealed class HomeUIState {
object Loading : HomeUIState()
data class Error(val homeErrorConfiguration: HomeErrorConfiguration) : HomeUIState()
data class Explore(val sectionList: List<Section>) : HomeUIState()
}
val uiState: Flow<HomeUIState> = homeInteractor.homeState.map { //map the result from what the business logic class is doing (call to repository and stuff) to an uiState}
inside my Composable Screen:
val uiState by homeViewModel.uiState.collectAsState(HomeUIState.Loading)
when (uiState) {
is HomeUIState.Error -> { //Displaying Error Screen}
is HomeUIState.Explore -> { //Displaying "success" screen}
else -> { //Displaying loading screen }
}
When opening the app it's working fine. I have the Loading -> Error or Loading -> Explore, but if a new event is trigger the app crash because inside the composable screen it's doing a cast inside the wrong switch.brandonmcansh
07/16/2021, 4:13 PMval viewState by rememberFlowWithLifecycle(viewModel.state)
.collectAsState(initial = PhotoDiscoveryViewState.Empty)
brandonmcansh
07/16/2021, 4:13 PM@Composable
fun <T> rememberFlowWithLifecycle(
flow: Flow<T>,
lifecycle: Lifecycle = LocalLifecycleOwner.current.lifecycle,
minActiveState: Lifecycle.State = Lifecycle.State.STARTED
): Flow<T> = remember(flow, lifecycle) {
flow.flowWithLifecycle(
lifecycle = lifecycle,
minActiveState = minActiveState
)
}
Lucien Guimaraes
07/16/2021, 4:16 PMflowWithLifecycle
is an API from which library ?brandonmcansh
07/16/2021, 4:16 PMbrandonmcansh
07/16/2021, 4:16 PMLucien Guimaraes
07/16/2021, 4:17 PMLucien Guimaraes
07/16/2021, 4:17 PMbrandonmcansh
07/16/2021, 4:22 PMChuck Jazdzewski [G]
07/16/2021, 4:25 PMLucien Guimaraes
07/16/2021, 4:49 PMLucien Guimaraes
07/16/2021, 4:50 PMLucien Guimaraes
07/16/2021, 5:08 PMbrandonmcansh
07/16/2021, 5:11 PMLucien Guimaraes
07/16/2021, 5:12 PMbrandonmcansh
07/16/2021, 5:13 PMbrandonmcansh
07/16/2021, 5:13 PMbrandonmcansh
07/16/2021, 5:13 PMbrandonmcansh
07/16/2021, 5:14 PMLucien Guimaraes
07/16/2021, 5:19 PMthose objects don’t equal
so they can’t cast acrossWhat do you mean by that ? 🤔 I'm not sure to understand
miqbaldc
07/17/2021, 5:37 PMdata class
instead of using sealed class
when collecting the state? cmiiwbrandonmcansh
07/17/2021, 5:39 PMis
and aren't actually equal entitiesLucien Guimaraes
07/19/2021, 8:38 AMLucien Guimaraes
07/19/2021, 8:39 AMThe sealed class entities are only comparable viaYeah I know that but I don't know why you said it was an issue regarding my case, I'm already doing a comparison withand aren't actually equal entitiesis
is
miqbaldc
07/20/2021, 11:56 PMflowWithLifecycle
to fix ur crash?