Guilherme Almeida
03/22/2022, 5:36 PMLazyColumn with mostly TextFields inside I noticed they were all recomposing on every key stroke for any of the fields.
So if I type in something in the first field, the other fields, even though they did not change their value, will also recompose. After experimenting a bit I pinned it down to using the onFocusChanged modifier for these text fields. After removing the onFocusChanged modifier the text fields seem to skip composition. Is this the expected behaviour ?
Quick repro (I am using the the recomposeHighlighter to visualize recompositions):
val state = remember {
List(20) { it to "" }.toMutableStateMap()
}
LazyColumn(Modifier.fillMaxSize()) {
itemsIndexed(state.values.toList()) { index, string ->
TextField(
value = string,
onValueChange = { state[index] = it },
modifier = Modifier
.recomposeHighlighter()
.onFocusChanged { }
)
}
}myanmarking
03/22/2022, 7:46 PMGuilherme Almeida
03/22/2022, 8:29 PMmyanmarking
03/22/2022, 8:48 PMPaul Woitaschek
03/22/2022, 8:53 PMPaul Woitaschek
03/22/2022, 8:53 PMPaul Woitaschek
03/22/2022, 8:56 PMPaul Woitaschek
03/22/2022, 8:57 PMPaul Woitaschek
03/22/2022, 8:58 PMGuilherme Almeida
03/22/2022, 9:02 PMGuilherme Almeida
03/22/2022, 9:05 PMmyanmarking
03/22/2022, 9:06 PMGuilherme Almeida
03/22/2022, 9:06 PMGuilherme Almeida
03/22/2022, 9:07 PMmyanmarking
03/22/2022, 9:09 PMGuilherme Almeida
03/23/2022, 12:12 PMonFocusChanged modifier is created, so If the modifier is created in the main composable it recomposes for every new state there, if it is inside its own composable then it only recomposes when the state has changed.
Wrapping the modifier with remember also works, but does not seem ideal