Recomposition in compose - does it go through each node(composable) in the tree and checks if that nodes needs to be updated or not based on last state from slot table?
✅ 1
ritesh
03/06/2022, 3:33 AM
Copy code
@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.
a
Adam Powell
03/06/2022, 3:35 AM
ScreenContent
isn't what's reading the
.value
of the snapshot state objects being invalidated,
MainScreen
is
r
ritesh
03/06/2022, 3:45 AM
Thanks Adam, i was under the assumption that
re-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.
a
Adam Powell
03/06/2022, 3:54 AM
a parameter's value is controlled by the caller. For a parameter to change the caller must run to pass a new value
👍 2
r
ritesh
03/06/2022, 10:25 PM
a parameter's value is controlled by the caller. For a parameter to change the caller must run to pass a new value
also, this article by Zach cleared my doubts related to node invalidation