Bug P4
Status Update
Comments
mn...@google.com <mn...@google.com> #2
Thanks for taking the time to file this bug — it would help us debug if you are able to provide a minimum repro, or at least the code sample which triggers this error and more of the stack trace!
yo...@gmail.com <yo...@gmail.com> #3
Since the same crash occurs, I will provide the reproduction code below.
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusDirection
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusProperties
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.unit.dp
@Composable
fun TextFields() {
val monthLength = 2
val yearLength = 2
var month by remember { mutableStateOf(TextFieldValue("")) }
var year by remember { mutableStateOf(TextFieldValue("")) }
val focusRequesterMonth = remember { FocusRequester() }
val focusRequesterYear = remember { FocusRequester() }
val focusManager = LocalFocusManager.current
Row(verticalAlignment = Alignment.CenterVertically) {
TextField(
value = month,
onValueChange = { value ->
var newValue = value.text.take(monthLength)
if (newValue.length == monthLength) {
focusManager.moveFocus(FocusDirection.Next)
}
month = TextFieldValue(newValue)
},
singleLine = true,
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
keyboardActions = KeyboardActions {
focusManager.moveFocus(FocusDirection.Next)
},
modifier = Modifier.width(60.dp)
.focusRequester(focusRequesterMonth)
.focusProperties { next = focusRequesterYear },
)
Text(text = "/")
TextField(
value = year,
onValueChange = { value ->
val newValue = value.text.take(yearLength)
if (newValue.length == yearLength) {
focusManager.moveFocus(FocusDirection.Next)
}
year = TextFieldValue(newValue)
},
singleLine = true,
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
keyboardActions = KeyboardActions {
focusManager.moveFocus(FocusDirection.Next)
},
modifier = Modifier.width(60.dp)
.focusRequester(focusRequesterYear),
)
}
}
Jetpack Compose version: 1.7.3 (BOM: 2024.09.03)
Android Studio Build: Android Studio Ladybug | 2024.2.1
Kotlin version: 2.0.21
In the above code, a crash occurs when focusManager.moveFocus(FocusDirection.Next)
is executed as a result of text input. It does not crash when executed via KeyboardAction.
The stack trace is as follows below.
FATAL EXCEPTION: main
Process: com.example, PID: 6838
java.lang.IllegalStateException: ActiveParent must have a focusedChild
at androidx.compose.ui.focus.OneDimensionalFocusSearchKt.forwardFocusSearch(OneDimensionalFocusSearch.kt:53)
at androidx.compose.ui.focus.OneDimensionalFocusSearchKt.oneDimensionalFocusSearch--OM-vw8(OneDimensionalFocusSearch.kt:44)
at androidx.compose.ui.focus.FocusTraversalKt.focusSearch-0X8WOeE(FocusTraversal.kt:107)
at androidx.compose.ui.focus.FocusOwnerImpl.focusSearch-ULY8qGw(FocusOwnerImpl.kt:247)
at androidx.compose.ui.focus.FocusOwnerImpl.moveFocus-3ESFkO8(FocusOwnerImpl.kt:203)
at com.example.TextFieldsKt.TextFields$lambda$18$lambda$13$lambda$12(CreditCardInfoInputLayout.kt:43)
at com.example.TextFieldsKt.$r8$lambda$ThJ7sx8Mtl6Q_PLLOjt3HnH3O6Q(Unknown Source:0)
at com.example.TextFieldsKt$$ExternalSyntheticLambda2.invoke(D8$$SyntheticClass:0)
at androidx.compose.foundation.text.BasicTextFieldKt$BasicTextField$11$1.invoke(BasicTextField.kt:769)
at androidx.compose.foundation.text.BasicTextFieldKt$BasicTextField$11$1.invoke(BasicTextField.kt:767)
at androidx.compose.foundation.text.LegacyTextFieldState$onValueChange$1.invoke(CoreTextField.kt:1002)
at androidx.compose.foundation.text.LegacyTextFieldState$onValueChange$1.invoke(CoreTextField.kt:995)
at androidx.compose.foundation.text.TextFieldDelegate$Companion.onBlur$foundation_release(TextFieldDelegate.kt:396)
at androidx.compose.foundation.text.CoreTextFieldKt.endInputSession(CoreTextField.kt:1091)
at androidx.compose.foundation.text.CoreTextFieldKt.access$endInputSession(CoreTextField.kt:1)
at androidx.compose.foundation.text.CoreTextFieldKt$CoreTextField$focusModifier$1$1.invoke(CoreTextField.kt:327)
at androidx.compose.foundation.text.CoreTextFieldKt$CoreTextField$focusModifier$1$1.invoke(CoreTextField.kt:312)
at androidx.compose.ui.focus.FocusChangedNode.onFocusEvent(FocusChangedModifier.kt:59)
at androidx.compose.ui.focus.FocusEventModifierNodeKt.refreshFocusEventNodes(FocusEventModifierNode.kt:68)
at androidx.compose.ui.focus.FocusTransactionsKt.clearFocus(FocusTransactions.kt:138)
at androidx.compose.ui.focus.FocusTransactionsKt.clearChildFocus(FocusTransactions.kt:190)
at androidx.compose.ui.focus.FocusTransactionsKt.clearChildFocus$default(FocusTransactions.kt:187)
at androidx.compose.ui.focus.FocusTransactionsKt.requestFocusForChild(FocusTransactions.kt:215)
at androidx.compose.ui.focus.FocusTransactionsKt.performRequestFocus(FocusTransactions.kt:72)
at androidx.compose.ui.focus.FocusTransactionsKt.requestFocus-Mxy_nc0(FocusTransactions.kt:50)
at androidx.compose.ui.focus.FocusOwnerImpl$moveFocus$focusSearchSuccess$1.invoke(FocusOwnerImpl.kt:204)
at androidx.compose.ui.focus.FocusOwnerImpl$moveFocus$focusSearchSuccess$1.invoke(FocusOwnerImpl.kt:203)
at androidx.compose.ui.focus.FocusRequester.findFocusTargetNode$ui_release(FocusRequester.kt:73)
at androidx.compose.ui.focus.FocusOwnerImpl.focusSearch-ULY8qGw(FocusOwnerImpl.kt:243)
at androidx.compose.ui.focus.FocusOwnerImpl.moveFocus-3ESFkO8(FocusOwnerImpl.kt:203)
at com.example.TextFieldsKt.TextFields$lambda$18$lambda$13$lambda$12(CreditCardInfoInputLayout.kt:43)
at com.example.TextFieldsKt.$r8$lambda$ThJ7sx8Mtl6Q_PLLOjt3HnH3O6Q(Unknown Source:0)
at com.example.TextFieldsKt$$ExternalSyntheticLambda2.invoke(D8$$SyntheticClass:0)
at androidx.compose.foundation.text.BasicTextFieldKt$BasicTextField$11$1.invoke(BasicTextField.kt:769)
at androidx.compose.foundation.text.BasicTextFieldKt$BasicTextField$11$1.invoke(BasicTextField.kt:767)
at androidx.compose.foundation.text.LegacyTextFieldState$onValueChange$1.invoke(CoreTextField.kt:1002)
at androidx.compose.foundation.text.LegacyTextFieldState$onValueChange$1.invoke(CoreTextField.kt:995)
at androidx.compose.foundation.text.TextFieldKeyInput.apply(TextFieldKeyInput.kt:71)
at androidx.compose.foundation.text.TextFieldKeyInput.apply(TextFieldKeyInput.kt:75)
at androidx.compose.foundation.text.TextFieldKeyInput.process-ZmokQxo(TextFieldKeyInput.kt:91)
at androidx.compose.foundation.text.TextFieldKeyInputKt$textFieldKeyInput$2$1$1.invoke-ZmokQxo(TextFieldKeyInput.kt:261)
at androidx.compose.foundation.text.TextFieldKeyInputKt$textFieldKeyInput$2$1$1.invoke(TextFieldKeyInput.kt:261)
at androidx.compose.ui.input.key.KeyInputNode.onKeyEvent-ZmokQxo(KeyInputModifier.kt:80)
at androidx.compose.ui.focus.FocusOwnerImpl.dispatchKeyEvent-YhN2O0w(FocusOwnerImpl.kt:275)
at androidx.compose.ui.focus.FocusOwner.dispatchKeyEvent-YhN2O0w$default(FocusOwner.kt:142)
at androidx.compose.ui.platform.AndroidComposeView.dispatchKeyEvent(AndroidComposeView.android.kt:945)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1964)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1964)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1964)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1964)
at com.android.internal.policy.DecorView.superDispatchKeyEvent(DecorView.java:490)
at com.android.internal.policy.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1880)
at android.app.Activity.dispatchKeyEvent(Activity.java:4156)
at androidx.core.app.ComponentActivity.superDispatchKeyEvent(ComponentActivity.kt:103)
at androidx.core.view.KeyEventDispatcher.dispatchKeyEvent(KeyEventDispatcher.java:85)
at androidx.core.app.ComponentActivity.dispatchKeyEvent(ComponentActivity.kt:117)
at com.android.internal.policy.DecorView.dispatchKeyEvent(DecorView.java:404)
at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:6275)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:6141)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5623)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5680)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5646)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:5811)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5654)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:5868)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5627)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5680)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5646)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5654)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5627)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:8558)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:8509)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:8478)
at android.view.ViewRootImpl$ViewRootHandler.handleMessageImpl(ViewRootImpl.java:5388)
at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:5260)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7842)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
gr...@google.com <gr...@google.com> #4
Possibly related
Description
Jetpack Compose component used:
Android Studio Build: Android Studio Koala | 2024.1.1 Patch 1
Kotlin version: 2.0.20
I have a code for moving focus and it have been working properly.
I updated compose version to 1.7.3 now I get this error:
java.lang.IllegalStateException: ActiveParent must have a focusedChild
this is my code:
focusManager.moveFocus(FocusDirection.Next)