Refactors search screen to make the SearchTextField @Stable
This commit is contained in:
@@ -224,6 +224,7 @@ private fun SearchBar(
|
|||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: (String) -> Unit
|
nav: (String) -> Unit
|
||||||
) {
|
) {
|
||||||
|
val scope = rememberCoroutineScope()
|
||||||
val listState = rememberLazyListState()
|
val listState = rememberLazyListState()
|
||||||
|
|
||||||
// Create a channel for processing search queries.
|
// Create a channel for processing search queries.
|
||||||
@@ -270,7 +271,11 @@ private fun SearchBar(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// LAST ROW
|
// LAST ROW
|
||||||
SearchTextField(searchBarViewModel, searchTextChanges)
|
SearchTextField(searchBarViewModel) {
|
||||||
|
scope.launch(Dispatchers.IO) {
|
||||||
|
searchTextChanges.trySend(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
DisplaySearchResults(listState, searchBarViewModel, nav, accountViewModel)
|
DisplaySearchResults(listState, searchBarViewModel, nav, accountViewModel)
|
||||||
}
|
}
|
||||||
@@ -278,10 +283,8 @@ private fun SearchBar(
|
|||||||
@Composable
|
@Composable
|
||||||
private fun SearchTextField(
|
private fun SearchTextField(
|
||||||
searchBarViewModel: SearchBarViewModel,
|
searchBarViewModel: SearchBarViewModel,
|
||||||
searchTextChanges: kotlinx.coroutines.channels.Channel<String>
|
onTextChanges: (String) -> Unit
|
||||||
) {
|
) {
|
||||||
val scope = rememberCoroutineScope()
|
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(10.dp)
|
.padding(10.dp)
|
||||||
@@ -293,9 +296,7 @@ private fun SearchTextField(
|
|||||||
value = searchBarViewModel.searchValue,
|
value = searchBarViewModel.searchValue,
|
||||||
onValueChange = {
|
onValueChange = {
|
||||||
searchBarViewModel.updateSearchValue(it)
|
searchBarViewModel.updateSearchValue(it)
|
||||||
scope.launch(Dispatchers.IO) {
|
onTextChanges(it)
|
||||||
searchTextChanges.trySend(it)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
shape = RoundedCornerShape(25.dp),
|
shape = RoundedCornerShape(25.dp),
|
||||||
keyboardOptions = KeyboardOptions.Default.copy(
|
keyboardOptions = KeyboardOptions.Default.copy(
|
||||||
|
|||||||
Reference in New Issue
Block a user