From 3a9a3f9e83699236ecae6621a142fc00edf046b3 Mon Sep 17 00:00:00 2001 From: Marco Romano Date: Thu, 31 Aug 2023 12:08:21 +0200 Subject: [PATCH] Focus on question field when opening screen. (#1194) --- .../poll/impl/create/CreatePollView.kt | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/features/poll/impl/src/main/kotlin/io/element/android/features/poll/impl/create/CreatePollView.kt b/features/poll/impl/src/main/kotlin/io/element/android/features/poll/impl/create/CreatePollView.kt index 3e3ec4eb16..ceb9513545 100644 --- a/features/poll/impl/src/main/kotlin/io/element/android/features/poll/impl/create/CreatePollView.kt +++ b/features/poll/impl/src/main/kotlin/io/element/android/features/poll/impl/create/CreatePollView.kt @@ -25,12 +25,19 @@ import androidx.compose.foundation.layout.imePadding import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.itemsIndexed +import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Add import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.remember import androidx.compose.ui.Modifier +import androidx.compose.ui.focus.FocusRequester +import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.input.ImeAction +import androidx.compose.ui.text.input.KeyboardCapitalization import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.unit.dp import io.element.android.features.poll.impl.R @@ -68,6 +75,10 @@ fun CreatePollView( onSubmitClicked = { state.eventSink(CreatePollEvents.NavBack) }, onDismiss = { state.eventSink(CreatePollEvents.HideConfirmation) } ) + val questionFocusRequester = remember { FocusRequester() } + LaunchedEffect(Unit) { + questionFocusRequester.requestFocus() + } Scaffold( modifier = modifier, topBar = { @@ -113,10 +124,13 @@ fun CreatePollView( onValueChange = { state.eventSink(CreatePollEvents.SetQuestion(it)) }, - modifier = Modifier.fillMaxWidth(), + modifier = Modifier + .focusRequester(questionFocusRequester) + .fillMaxWidth(), placeholder = { Text(text = stringResource(id = R.string.screen_create_poll_question_hint)) }, + keyboardOptions = keyboardOptions, ) } ) @@ -133,6 +147,7 @@ fun CreatePollView( placeholder = { Text(text = stringResource(id = R.string.screen_create_poll_answer_hint, index + 1)) }, + keyboardOptions = keyboardOptions, ) }, trailingContent = ListItemContent.Custom { @@ -185,3 +200,8 @@ internal fun CreatePollViewPreview( state = state, ) } + +private val keyboardOptions = KeyboardOptions.Default.copy( + capitalization = KeyboardCapitalization.Sentences, + imeAction = ImeAction.Next, +)