From 9cc37d0a123bc8a6bd7ccad5827c96d2316688d4 Mon Sep 17 00:00:00 2001 From: DeathKhan Date: Thu, 12 Nov 2026 19:11:34 -0600 Subject: [PATCH] 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. --- .../java/com/droiddeck/launcher/ui/StoresPage.kt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/ui/StoresPage.kt b/app/src/main/java/com/droiddeck/launcher/ui/StoresPage.kt index 7bc7c186d0..4e2c210b62 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/StoresPage.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/StoresPage.kt @@ -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