Brian Norman
05/01/2020, 3:43 PM@Model
object into the Search Bar composable from the parent then it'll get reset every time I type (I'm guessing this is because the parent re-renders causing the Search Bar re-renders)...
If anyone's done this and could share how they've done it or point me in the right direction that would be super helpful! Thanks 🙂Kazemihabib1996
05/01/2020, 3:50 PMBrian Norman
05/01/2020, 3:55 PM@Model
class SearchState(
var textField : TextFieldValue = TextFieldValue()
)
@Composable
fun SearchBar(searchState: SearchState) {
Surface(color = Color.LightGray, modifier = Modifier.padding(16.dp), shape = RoundedCornerShape(5.dp)) {
TextField(
value = searchState.textField,
modifier = Modifier.padding(16.dp) + Modifier.fillMaxWidth(),
imeAction = ImeAction.Search,
onValueChange = { searchState.textField = it }
)
}
}
@Composable
private fun FeedContent(
modifier: Modifier,
entriesList: List<Entry>,
searchState: SearchState = SearchState()
) {
Stack(modifier = modifier.fillMaxSize()) {
VerticalScroller {
Column {
SearchBar(searchState)
for (entry in entriesList) {
if (entry.restaurant.toLowerCase().contains(searchState.textField.text.toLowerCase())) {
Clickable(onClick = { navigateTo(Screen.Entry(entry)) }) {
FeedCard(entry = entry)
}
}
}
}
}
}
}
Kazemihabib1996
05/01/2020, 4:00 PMremeber {SearchState()}
?Brian Norman
05/01/2020, 4:00 PMremember
to fully wrap my head around how that works, but thank you!Kazemihabib1996
05/01/2020, 4:02 PMsearchState.textField
inside FeedContent every time it changes FeedContent
is recomposed and you have a new SearchState()
remeber
is kind of like C languages static variables(First I read about remeber
I thought about it like this)Brian Norman
05/01/2020, 4:05 PM