Skip to content

Instantly share code, notes, and snippets.

@mirokolodii
Created December 1, 2023 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mirokolodii/d455ff64ca095f4937df2478f1ef0229 to your computer and use it in GitHub Desktop.
Save mirokolodii/d455ff64ca095f4937df2478f1ef0229 to your computer and use it in GitHub Desktop.
Search box with icons and edit text
@Composable
fun SearchBox(
onBackClick: () -> Unit,
) {
var searchText by remember { mutableStateOf("") }
Row(
horizontalArrangement = Arrangement.spaced(16.dp),
) {
Icon(
vector = Icons.Default.BackArrow,
modifier = Modifier.clickable { onBackClick() }
)
BasicTextField(
onValueChange = { value ->
searchText = value
onNewSearchText(value)
}
)
// Show 'clear text' icon only when text field has some value
if (!searchText.isBlank()) {
Icon(
vector = Icons.Default.BackArrow,
modifier = Modifier.clickable { searchText = "" }
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment