SearchApplications

@Composable
fun SearchApplications(modifier: Modifier = Modifier, onSearch: (String) -> Unit)

This function displays a search bar for the application.

Parameters

modifier

The modifier to be applied to the search bar.

query

The query to be displayed in the search bar.

onQueryChange

The action to be performed when the query is changed.

onSearch

The action to be performed when the search is performed.

active

The state of the search bar.

onActiveChange

The action to be performed when the search bar state is changed.

placeholder

The placeholder to be displayed in the search bar.

leadingIcon

The leading icon to be displayed in the search bar.

trailingIcon

The trailing icon to be displayed in the search bar.

Example usage:

SearchBar(
modifier = Modifier,
query = text,
onQueryChange = {
text = it
onSearch(it)
},
onSearch = {
active = false
if (searchHistory.contains(it).not())
searchHistory.add(it)
onSearch(it)
},
active = false,
onActiveChange = {
active = it
},
placeholder = {
Text(text = "Ex: Camera", fontWeight = FontWeight.Thin)
},
leadingIcon = {
Icon(imageVector = Icons.Default.Search, contentDescription = "Search icon")
},
trailingIcon = {
if (active) {
Icon(
modifier = Modifier.clickable {
if (text.isNotEmpty()) {
text = ""
} else {
active = false
}
},
imageVector = Icons.Default.Close,
contentDescription = "Close icon"
)
}
},
) {}