From 95eeb26ae18b2c04fd50c9228e1a3e706724730f Mon Sep 17 00:00:00 2001 From: Troy Rijkaard Date: Mon, 2 Oct 2023 22:33:25 +0100 Subject: [PATCH] feat: pressing done should perform search When on the search screen, if the done button is pressed on the software keyboard it should perform the search and close the keyboard. --- .../nekome/app/search/host/ui/HostScreen.kt | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/features/search/src/main/java/com/chesire/nekome/app/search/host/ui/HostScreen.kt b/features/search/src/main/java/com/chesire/nekome/app/search/host/ui/HostScreen.kt index 2ea68904f..5e375755f 100644 --- a/features/search/src/main/java/com/chesire/nekome/app/search/host/ui/HostScreen.kt +++ b/features/search/src/main/java/com/chesire/nekome/app/search/host/ui/HostScreen.kt @@ -18,6 +18,7 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.foundation.shape.CircleShape +import androidx.compose.foundation.text.KeyboardActions import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Add @@ -109,7 +110,12 @@ private fun Render( .padding(paddingValues), horizontalAlignment = Alignment.CenterHorizontally ) { - InputText(state.value.searchText, state.value.isSearchTextError, onInputTextChanged) + InputText( + state.value.searchText, + state.value.isSearchTextError, + onInputTextChanged, + onSearchPressed + ) SearchGroup(state.value.searchGroup, onSearchGroupSelected) if (state.value.isSearching) { CircularProgressIndicator() @@ -132,7 +138,14 @@ private fun Render( } @Composable -private fun InputText(text: String, isError: Boolean, onInputTextChanged: (String) -> Unit) { +private fun InputText( + text: String, + isError: Boolean, + onInputTextChanged: (String) -> Unit, + onDonePressed: () -> Unit +) { + val keyboardController = LocalSoftwareKeyboardController.current + OutlinedTextField( value = text, onValueChange = onInputTextChanged, @@ -140,6 +153,12 @@ private fun InputText(text: String, isError: Boolean, onInputTextChanged: (Strin keyboardType = KeyboardType.Text, autoCorrect = false ), + keyboardActions = KeyboardActions( + onDone = { + onDonePressed() + keyboardController?.hide() + } + ), singleLine = true, label = { Text(text = stringResource(id = StringResource.search_series_title)) }, isError = isError,