mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-19 16:55:26 +02:00
Fixed UnittoSearchBar
This commit is contained in:
parent
948791aff0
commit
e04051950b
@ -75,25 +75,20 @@ fun UnittoSearchBar(
|
|||||||
var showSearchInput by remember { mutableStateOf(false) }
|
var showSearchInput by remember { mutableStateOf(false) }
|
||||||
val focusRequester = remember { FocusRequester() }
|
val focusRequester = remember { FocusRequester() }
|
||||||
|
|
||||||
fun stagedNavigateUp() {
|
LaunchedEffect(showSearchInput) {
|
||||||
if (showSearchInput) {
|
if (showSearchInput) focusRequester.requestFocus() else onQueryChange(TextFieldValue())
|
||||||
// Search text field is open, need to close it and clear search query
|
|
||||||
showSearchInput = false
|
|
||||||
// focusManager.clearFocus()
|
|
||||||
onQueryChange(TextFieldValue())
|
|
||||||
} else {
|
|
||||||
// No search text field is shown, can go back as usual
|
|
||||||
navigateUp()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TopAppBar(
|
BackHandler(showSearchInput) { showSearchInput = false }
|
||||||
|
|
||||||
|
Crossfade(
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
title = {
|
targetState = showSearchInput,
|
||||||
Crossfade(showSearchInput, label = "Search input") { showSearch ->
|
label = "Search input"
|
||||||
|
) { showSearch ->
|
||||||
if (showSearch) {
|
if (showSearch) {
|
||||||
LaunchedEffect(Unit) { focusRequester.requestFocus() }
|
TopAppBar(
|
||||||
|
title = {
|
||||||
SearchTextField(
|
SearchTextField(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.focusRequester(focusRequester)
|
.focusRequester(focusRequester)
|
||||||
@ -103,36 +98,42 @@ fun UnittoSearchBar(
|
|||||||
onValueChange = onQueryChange,
|
onValueChange = onQueryChange,
|
||||||
onSearch = {}
|
onSearch = {}
|
||||||
)
|
)
|
||||||
} else {
|
|
||||||
Text(
|
|
||||||
text = title,
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
style = MaterialTheme.typography.titleLarge
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
navigationIcon = {
|
navigationIcon = {
|
||||||
NavigateUpButton { stagedNavigateUp() }
|
NavigateUpButton { showSearchInput = false }
|
||||||
},
|
},
|
||||||
actions = {
|
actions = {
|
||||||
Crossfade(showSearchInput, label = "Search unit") { showSearch ->
|
|
||||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||||
if (showSearch) {
|
|
||||||
ClearButton(visible = query.text.isNotEmpty()) { onQueryChange(TextFieldValue()) }
|
ClearButton(visible = query.text.isNotEmpty()) { onQueryChange(TextFieldValue()) }
|
||||||
searchActions()
|
searchActions()
|
||||||
} else {
|
|
||||||
SearchButton { showSearchInput = true }
|
|
||||||
noSearchActions()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
scrollBehavior = scrollBehavior,
|
scrollBehavior = scrollBehavior,
|
||||||
colors = colors,
|
colors = colors,
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
BackHandler { stagedNavigateUp() }
|
TopAppBar(
|
||||||
|
title = {
|
||||||
|
Text(
|
||||||
|
text = title,
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
style = MaterialTheme.typography.titleLarge
|
||||||
|
)
|
||||||
|
},
|
||||||
|
navigationIcon = {
|
||||||
|
NavigateUpButton { navigateUp() }
|
||||||
|
},
|
||||||
|
actions = {
|
||||||
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||||
|
SearchButton { showSearchInput = true }
|
||||||
|
noSearchActions()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
scrollBehavior = scrollBehavior,
|
||||||
|
colors = colors,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
Loading…
x
Reference in New Issue
Block a user