Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Alignment
Expand Down Expand Up @@ -104,6 +105,15 @@ fun MainSearchBar(
// Get keyboard controller inside Popup since it has its own window
val keyboardController = LocalSoftwareKeyboardController.current

val triggerSearch = {
val trimmed = query.trim()
if (trimmed.isNotEmpty()) {
searchLocation.value = userLocation
keyboardController?.hide()
searchFunctions.onTriggerSearch(trimmed)
}
}

// Request focus on the text field when the search overlay opens
LaunchedEffect(expanded) {
if (expanded) {
Expand Down Expand Up @@ -148,14 +158,7 @@ fun MainSearchBar(
textStyle = textStyle,
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Search),
keyboardActions = KeyboardActions(
onSearch = {
val trimmed = query.trim()
if (trimmed.isNotEmpty()) {
searchLocation.value = userLocation
keyboardController?.hide()
searchFunctions.onTriggerSearch(trimmed)
}
}
onSearch = { triggerSearch() }
),
modifier = Modifier
.weight(1f)
Expand All @@ -174,6 +177,12 @@ fun MainSearchBar(
)

if (query.isNotEmpty()) {
TextButton(onClick = { triggerSearch() }) {
Text(
text = stringResource(R.string.search_button_label),
color = colors.primary
)
}
IconButton(
onClick = { query = "" }
) {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
<string name="settings_units_metric">"Metric (Meters)"</string>
<!-- In the Settings page the title of the section for selecting which search system to use -->
<string name="settings_section_search">"Search"</string>
<!-- Label for the inline Search button next to the search input field -->
<string name="search_button_label">"Search"</string>
<!-- A hint for the search bar explaining what it's for -->
<string name="search_bar_hint">"Type a destination name or address"</string>
<!-- This is the setting to control whether the Search uses offline data or can use an online server -->
Expand Down