Bug P2
Status Update
Comments
da...@mullvad.net <da...@mullvad.net> #2
Any news about this issue?
da...@mullvad.net <da...@mullvad.net> #3
Any news about this issue?
da...@mullvad.net <da...@mullvad.net> #4
I have the same issue.
Jetpack Compose version: 1.0.2
My code:
@ExperimentalComposeUiApi
@Composable
fun Code(modifier: Modifier = Modifier, onCodeInputted: (String) -> Unit = {}) {
val passcodeLength = 6
val codeArray = remember {
Array(passcodeLength) {
mutableStateOf(TextFieldValue(text = ""))
}
}
val focusRequesters = remember {
(0 until passcodeLength).map { FocusRequester() }
}
Row(modifier = modifier) {
repeat(passcodeLength) { textFieldIndex ->
OutlinedTextField(
modifier = Modifier
.weight(1f)
.onPreviewKeyEvent {
if (it.type == KeyEventType.KeyDown && it.key == Key.Backspace &&
textFieldIndex != 0 && codeArray[textFieldIndex].value.text.isEmpty()
) {
codeArray[textFieldIndex - 1].value =
codeArray[textFieldIndex - 1].value.copy(text = "")
focusRequesters[textFieldIndex - 1].requestFocus()
}
false
}
.focusRequester(focusRequesters[textFieldIndex]),
value = codeArray[textFieldIndex].value,
textStyle = LocalTextStyle.current.copy(
textAlign = TextAlign.Center
),
singleLine = true,
keyboardOptions = KeyboardOptions.Default.copy(
keyboardType = KeyboardType.Number,
imeAction = ImeAction.Next
),
onValueChange = { newTextFieldValue ->
val newString = newTextFieldValue.text
if (newString.isDigitsOnly() && codeArray[textFieldIndex].value.text != newString) {
codeArray[textFieldIndex].value =
if (newString.length > 1) {
newTextFieldValue.copy(text = newString[0].toString())
} else newTextFieldValue
if (newString != "") {
val nextEmpty =
codeArray.indices.firstOrNull { codeArray[it].value.text == "" }
if (nextEmpty != null) {
focusRequesters[nextEmpty].requestFocus()
} else {
onCodeInputted(codeArray.joinToString(separator = "") { it.value.text })
}
}
}
}
)
if (textFieldIndex != passcodeLength - 1) {
Spacer(Modifier.width(10.dp))
}
}
}
}
pj...@gmail.com <pj...@gmail.com> #5
Any info about this issue? :)
kl...@google.com <kl...@google.com> #6
Does any hacky workaround exists?
da...@mullvad.net <da...@mullvad.net> #7
Still nothing?
Description
TextField with
singleLine = true
does not consume the enter key. It passedimeOptions(singleLine = true)
but IME never consumes the click. This becomes a problem when using a TextField in a dialog since focus is still on a list item in the back. Pressing enter while focusing the TextField will then cause the button in the list view in the background to be pressed again.Here is a snippet with the issue at hand:
I've also attached a recording of the issue, I first navigate with keyboard enter the dialog and focus the TextField, enter some text and then press enter to finish my modification. This causes the dialog to close but also trigger a onClick on the button (named "Row 2") in the background thus causing the dialog to open again. On the second dialog I go to the "Confirm" button and press enter instead, this correctly consumes the press and simply closes the dialog.