Skip to content

Commit

Permalink
feat: pressing done should perform search
Browse files Browse the repository at this point in the history
When on the search screen, if the done button is pressed on the software keyboard it should perform
the search and close the keyboard.
  • Loading branch information
Chesire committed Oct 2, 2023
1 parent 9efe2e8 commit 95eeb26
Showing 1 changed file with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -132,14 +138,27 @@ 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,
keyboardOptions = KeyboardOptions.Default.copy(
keyboardType = KeyboardType.Text,
autoCorrect = false
),
keyboardActions = KeyboardActions(
onDone = {
onDonePressed()
keyboardController?.hide()
}
),
singleLine = true,
label = { Text(text = stringResource(id = StringResource.search_series_title)) },
isError = isError,
Expand Down

0 comments on commit 95eeb26

Please sign in to comment.