Skip to content

Instantly share code, notes, and snippets.

@SahDavies
Created July 23, 2025 03:20
Show Gist options
  • Select an option

  • Save SahDavies/db14dfb7406170d9ca384cbb2011f89a to your computer and use it in GitHub Desktop.

Select an option

Save SahDavies/db14dfb7406170d9ca384cbb2011f89a to your computer and use it in GitHub Desktop.
@Composable
fun SearchDialog(
modifier: Modifier = Modifier,
placeholder: String = "Search",
searchDialogState: SearchDialogState,
onSelectItem: (String) -> Unit
) {
Box(...) {
var text by searchDialogState.query
ViewState(text = text.ifEmpty { placeholder }, onCLick = { searchDialogState.updateViewState() })
if (searchDialogState.isSearch()) {
SearchState(
suggestions = searchDialogState.suggestions.collectAsStateWithLifecycle().value,
searchTerm = searchDialogState.query,
isError = searchDialogState.foundMatch.not(),
onQueryChange = { query ->
searchDialogState.query = query
searchDialogState.queryFlow.value = query
},
onSelectSuggestion = {
onSelectItem(it)
searchDialogState.query = it
searchDialogState.queryFlow.value = it
searchDialogState.updateViewState()
}
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment