Focus on question field when opening screen. (#1194)
This commit is contained in:
parent
b16dc45754
commit
3a9a3f9e83
1 changed files with 21 additions and 1 deletions
|
|
@ -25,12 +25,19 @@ import androidx.compose.foundation.layout.imePadding
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.itemsIndexed
|
import androidx.compose.foundation.lazy.itemsIndexed
|
||||||
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.Add
|
import androidx.compose.material.icons.filled.Add
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Modifier
|
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.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.tooling.preview.PreviewParameter
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import io.element.android.features.poll.impl.R
|
import io.element.android.features.poll.impl.R
|
||||||
|
|
@ -68,6 +75,10 @@ fun CreatePollView(
|
||||||
onSubmitClicked = { state.eventSink(CreatePollEvents.NavBack) },
|
onSubmitClicked = { state.eventSink(CreatePollEvents.NavBack) },
|
||||||
onDismiss = { state.eventSink(CreatePollEvents.HideConfirmation) }
|
onDismiss = { state.eventSink(CreatePollEvents.HideConfirmation) }
|
||||||
)
|
)
|
||||||
|
val questionFocusRequester = remember { FocusRequester() }
|
||||||
|
LaunchedEffect(Unit) {
|
||||||
|
questionFocusRequester.requestFocus()
|
||||||
|
}
|
||||||
Scaffold(
|
Scaffold(
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
topBar = {
|
topBar = {
|
||||||
|
|
@ -113,10 +124,13 @@ fun CreatePollView(
|
||||||
onValueChange = {
|
onValueChange = {
|
||||||
state.eventSink(CreatePollEvents.SetQuestion(it))
|
state.eventSink(CreatePollEvents.SetQuestion(it))
|
||||||
},
|
},
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier
|
||||||
|
.focusRequester(questionFocusRequester)
|
||||||
|
.fillMaxWidth(),
|
||||||
placeholder = {
|
placeholder = {
|
||||||
Text(text = stringResource(id = R.string.screen_create_poll_question_hint))
|
Text(text = stringResource(id = R.string.screen_create_poll_question_hint))
|
||||||
},
|
},
|
||||||
|
keyboardOptions = keyboardOptions,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
@ -133,6 +147,7 @@ fun CreatePollView(
|
||||||
placeholder = {
|
placeholder = {
|
||||||
Text(text = stringResource(id = R.string.screen_create_poll_answer_hint, index + 1))
|
Text(text = stringResource(id = R.string.screen_create_poll_answer_hint, index + 1))
|
||||||
},
|
},
|
||||||
|
keyboardOptions = keyboardOptions,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
trailingContent = ListItemContent.Custom {
|
trailingContent = ListItemContent.Custom {
|
||||||
|
|
@ -185,3 +200,8 @@ internal fun CreatePollViewPreview(
|
||||||
state = state,
|
state = state,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val keyboardOptions = KeyboardOptions.Default.copy(
|
||||||
|
capitalization = KeyboardCapitalization.Sentences,
|
||||||
|
imeAction = ImeAction.Next,
|
||||||
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue