fal
03/14/2021, 3:07 AM@Composable
fun HelloScreen(helloViewModel: HelloViewModel = viewModel()) {
val state: HelloState by helloViewModel.stateFlow.collectAsState(initialState)
Column {
Text(state.title)
SomeStatelessComponent(state.componentValue)
SomeOtherStatelessComponent(state.otherComponentValue)
...
}
}
The idea is that every composable used in HelloScreen are simply stateless composables. My worry is that this won't work out great if compose simply does a reference check (===) instead of an equals to check if it should recompose these stateless composables. If compose simply does a reference check, I see three ways out of this:
• Wrapping every object in this state class in mutableStateOf and adjust the reducer on the viewmodel side -> seems terrible, does this even work?
• Having a stateflow per state value -> seems clunky if your screen has a lot of state properties.
• Orrr find a way to selectively "subscribe" to the stateFlow properties, like
stateFlow.map { state -> state.componentValue }.distinctUntilChanged()
Is this okay? I'm up for other ideasAdam Powell
03/14/2021, 3:18 AM@Stable
or @Immutable
as appropriate) compose will skip a child composable function call if all parameters are `==/
.equals.`fal
03/14/2021, 3:22 AMAdam Powell
03/14/2021, 3:24 AMfal
03/14/2021, 3:26 AMJason Ankers
03/14/2021, 4:06 AMAdam Powell
03/14/2021, 2:15 PMfal
03/15/2021, 3:17 AMAdam Powell
03/15/2021, 3:01 PMAdam Powell
03/15/2021, 3:02 PMfal
03/15/2021, 3:52 PM