mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
fix(ui): header search keeps the header height and returns focus when it closes (#2543)
* fix(ui): keep the header height when search opens The search field in the page header reserved a line for its empty label, which made the open field taller than the header row and pushed the page down. * fix(ui): return focus to the search button when search closes Closing the header search with Back removed the field while it held focus, so the highlight was lost. The search button takes focus once it is back on screen.
This commit is contained in:
1 parent
bd4bfce3af
commit
9cc37d0a12
1 file changed
+11
-2
@@ -13,6 +13,7 @@ import androidx.compose.material.icons.outlined.Folder
|
||||
import androidx.compose.material.icons.outlined.SdCard
|
||||
import androidx.compose.material.icons.outlined.Smartphone
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusProperties
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.focus.onFocusChanged
|
||||
@@ -1072,12 +1073,20 @@ internal fun ModeHeader(
|
||||
var searching by remember { mutableStateOf(query.isNotEmpty()) }
|
||||
var focusOnOpen by remember { mutableStateOf(false) }
|
||||
val open by animateFloatAsState(if (searching) 1f else 0f, Motion.sp(0.75f, 420f), label = "searchOpen")
|
||||
// Closing takes the field away with focus still in it; the search button gets it once it is back on screen.
|
||||
val searchIcon = remember { FocusRequester() }
|
||||
var toIcon by remember { mutableStateOf(false) }
|
||||
val close = {
|
||||
searching = false
|
||||
focusOnOpen = false
|
||||
toIcon = true
|
||||
if (query.isNotEmpty()) onQuery("")
|
||||
}
|
||||
BackHandler(enabled = searching && !clearSearchFocus) { close() }
|
||||
LaunchedEffect(toIcon, searching, open <= 0.01f) {
|
||||
if (searching) toIcon = false
|
||||
else if (toIcon && open <= 0.01f) { focusSoon { searchIcon }; toIcon = false }
|
||||
}
|
||||
val heading: @Composable () -> Unit = {
|
||||
if (lead != null) lead()
|
||||
else Text(
|
||||
@@ -1093,7 +1102,7 @@ internal fun ModeHeader(
|
||||
Box(Modifier.width(w).graphicsLayer { alpha = (open * 1.6f).coerceAtMost(1f) }) {
|
||||
AdbTextField(
|
||||
value = query, onValueChange = onQuery, label = "", keyboardType = KeyboardType.Text, imeAction = ImeAction.Search,
|
||||
placeholder = placeholder, compact = true, focusOnShow = focusOnOpen,
|
||||
placeholder = placeholder, compact = true, showLabel = false, focusOnShow = focusOnOpen,
|
||||
clearFocus = clearSearchFocus || !searching,
|
||||
onFocusChange = { focused -> if (!focused && query.isEmpty()) { searching = false; focusOnOpen = false } },
|
||||
)
|
||||
@@ -1103,7 +1112,7 @@ internal fun ModeHeader(
|
||||
}
|
||||
}
|
||||
val searchButton: @Composable () -> Unit = {
|
||||
SearchIcon(stringResource(R.string.stores_search_open)) { searching = true; focusOnOpen = true }
|
||||
Box(Modifier.focusRequester(searchIcon)) { SearchIcon(stringResource(R.string.stores_search_open)) { searching = true; focusOnOpen = true } }
|
||||
}
|
||||
BoxWithConstraints(Modifier.fillMaxWidth()) {
|
||||
val stacked = maxWidth < NarrowPaneWidth
|
||||
|
||||
Reference in new issue
Block a user