ritesh
03/06/2022, 2:52 AM@Composable
fun MainScreen(viewModel:Vm){
// live-data in vm
when (viewModel.response.observeAsState().value) {
//
}
ScreenContent(
sate = viewModel.emailState.collectAsState().value,
onValueChanged: viewModel::valueChanged
)
}
@Composable
fun ScreenContent(
state:SomeState,
onValueChanged:(String) -> Unit
){
TextField(value = state.text, onValueChange = onValueChanged)
}
Why MainScreen
Composable, is called(recomposed/invalidated) again when ScreenContent
is changed. I believe only ScreenContent
should be recomposed in this case.Adam Powell
03/06/2022, 3:35 AMScreenContent
isn't what's reading the .value
of the snapshot state objects being invalidated, MainScreen
isritesh
03/06/2022, 3:45 AMre-composition
is based on parameters passed down in the tree hierarchy, and if there is a difference from last state, only that composable will re-compose, not the parent node.Adam Powell
03/06/2022, 3:54 AMritesh
03/06/2022, 10:25 PMa parameter's value is controlled by the caller. For a parameter to change the caller must run to pass a new valuealso, this article by Zach cleared my doubts related to node invalidation