Marco Pierucci
03/28/2021, 8:12 PMMarco Pierucci
03/28/2021, 8:12 PMdata class SearchState(
val query: String = "",
val drinks: List<Drink> = emptyList()
)
@Composable
fun SearchScreen(store: SearchStore) {
val state = store.state.collectAsState().value
val drinks = state.drinks
Column {
SearchToolbar(
query = state.query,
onQueryValueChanged = { querySlice ->
store.dispatch(SearchAction.AppendSearchQuery(querySlice))
},
onSearch = { searchQuery ->
store.dispatch(SearchAction.Search(searchQuery))
})
if (drinks.isEmpty()) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
modifier = Modifier
.fillMaxWidth()
.fillMaxHeight()
) {
Log.e("Recomposition ", "Column composable called")
Text(
text = "Your query yield no results",
color = MaterialTheme.colors.onBackground
)
}
} else {
LazyColumn {
items(drinks, { drink: Drink -> drink.id }) { drink ->
Text(drink.name, color = MaterialTheme.colors.onBackground)
}
}
}
}
}
Marco Pierucci
03/28/2021, 8:14 PMonQueryValueChanged
cause the store to re emit on the flow a new state where just query
changes. This happens in every key entered in a TextField within SearchToolbarMarco Pierucci
03/28/2021, 8:15 PMif (drinks.isEmpty()) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
modifier = Modifier
.fillMaxWidth()
.fillMaxHeight()
) {
Log.e("Recomposition ", "Column composable called")
Text(
text = "Your query yield no results",
color = MaterialTheme.colors.onBackground
)
}
}
should not be recomposed as there are no parameter changes, nevertheless with every input I can see my Log inputMarco Pierucci
03/28/2021, 8:17 PMAdam Powell
03/28/2021, 8:57 PMColumn
is `inline`d. You can verify this by ctrl+clicking into the definition of Column
and the other composables it calls.Marco Pierucci
03/28/2021, 9:03 PMMarco Pierucci
03/28/2021, 9:03 PMAdam Powell
03/28/2021, 9:09 PMMarco Pierucci
03/28/2021, 9:17 PMAdam Powell
03/28/2021, 9:30 PMMarco Pierucci
03/28/2021, 9:33 PMMarco Pierucci
03/28/2021, 9:33 PM