Fixed
Status Update
Comments
an...@google.com <an...@google.com>
za...@gmail.com <za...@gmail.com> #2
Any news about this issue?
za...@gmail.com <za...@gmail.com> #3
Any news about this issue?
an...@google.com <an...@google.com>
za...@gmail.com <za...@gmail.com> #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))
}
}
}
}
po...@google.com <po...@google.com>
kl...@google.com <kl...@google.com>
kl...@google.com <kl...@google.com> #5
Any info about this issue? :)
kl...@google.com <kl...@google.com> #6
Does any hacky workaround exists?
Description
Jetpack Compose release version: 1.0.0-alpha11
Android Studio Build:
This requires a bit of setup to reproduce, and there are a number of issues that require similar setup, so I have created a dedicated repo that demonstrates and has UI tests for them here .
The README in the root of that repo describes the setup, the issues, and the fixes to them that make sense to me.
These issues will probably affect the Compose integration for the Jetpack Navigation library, as well as other navigation libraries that are written in Compose.