From a526db6cd1c04a7d1559cda18274ec98f9d2b967 Mon Sep 17 00:00:00 2001 From: Seb3thehacker Date: Mon, 12 Oct 2026 17:09:51 -0700 Subject: [PATCH] templated search: keep the keyboard down when the app asks, so results opened by voice show --- .../gearslip/car/TemplateContent.kt | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/gearslip/src/main/java/app/seb3thehacker/gearslip/car/TemplateContent.kt b/gearslip/src/main/java/app/seb3thehacker/gearslip/car/TemplateContent.kt index cd3c04e..4b29ac9 100644 --- a/gearslip/src/main/java/app/seb3thehacker/gearslip/car/TemplateContent.kt +++ b/gearslip/src/main/java/app/seb3thehacker/gearslip/car/TemplateContent.kt @@ -45,6 +45,7 @@ import androidx.car.app.model.MessageTemplate import androidx.car.app.model.PaneTemplate import androidx.car.app.model.Row as CarRow import androidx.car.app.model.SearchTemplate +import androidx.compose.foundation.clickable import androidx.car.app.model.Section import androidx.car.app.model.SectionedItemTemplate import androidx.car.app.model.TabTemplate @@ -238,6 +239,9 @@ private fun SearchContent(template: SearchTemplate, modifier: Modifier) { // initialSearchText would fight whatever is being typed. var query by remember { mutableStateOf(template.initialSearchText.orEmpty()) } val delegate = template.searchCallbackDelegate + // An app that opens on results ("navigate to Starbucks") asks for the keyboard to stay down, + // so the results aren't hidden under it. Tapping the field brings it up. + var typing by remember { mutableStateOf(template.isShowKeyboardByDefault) } ContentSurface(modifier) { // Back button and field share a row: on a 480px screen the keyboard and the results @@ -251,7 +255,7 @@ private fun SearchContent(template: SearchTemplate, modifier: Modifier) { SearchField( query, template.searchHint.orEmpty(), - Modifier.weight(1f), + Modifier.weight(1f).clickable { typing = true }, onClear = { query = "" delegate.textChanged("") @@ -265,14 +269,17 @@ private fun SearchContent(template: SearchTemplate, modifier: Modifier) { else ItemListColumn(template.itemList, modifier = Modifier.fillMaxSize()) } - CarKeyboard( - text = query, - onTextChange = { - query = it - delegate.textChanged(it) - }, - onSubmit = { delegate.submitted(query) }, - ) + if (typing) { + CarKeyboard( + text = query, + onTextChange = { + query = it + delegate.textChanged(it) + }, + onSubmit = { delegate.submitted(query) }, + onDismiss = { typing = false }, + ) + } } }