Assigned
Status Update
Comments
rv...@google.com <rv...@google.com> #2
Assigning to Jetpack Compose team as the issue seems to be with LazyRow
and FocusRestorer
integration.
lp...@google.com <lp...@google.com>
co...@netplus.pro <co...@netplus.pro> #3
When I try with the last version 1.8.0-rc01 with this code :
var buttons by remember { mutableStateOf((1..10).toList()) }
val lineFocusRequester = remember { FocusRequester() }
val firstItemFocusRequester = remember { FocusRequester() }
Column {
Button(
onClick = { },
modifier = Modifier.padding(20.dp)
) {
Text("Hello")
}
LazyRow(
modifier = Modifier
.padding(16.dp)
.focusRequester(lineFocusRequester)
.focusRestorer(firstItemFocusRequester),
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
itemsIndexed(
items = buttons,
key = { index, _ -> index }
) { index, buttonId ->
Button(
onClick = {
buttons = buttons.filter { it != buttonId }
},
modifier = Modifier
.padding(4.dp)
.ifElse(index == 0, Modifier.focusRequester(firstItemFocusRequester))
) {
Text("Button $buttonId")
}
}
}
}
When I click on the last button the focus is lost and goes to the "Hello" button. And when I go down, the app is crashing :
Process: com.example.recomposetests, PID: 6000
java.lang.IllegalStateException:
FocusRequester is not initialized. Here are some possible fixes:
1. Remember the FocusRequester: val focusRequester = remember { FocusRequester() }
2. Did you forget to add a Modifier.focusRequester() ?
3. Are you attempting to request focus during composition? Focus requests should be made in response to some event. Eg Modifier.clickable { focusRequester.requestFocus() }
at androidx.compose.ui.focus.FocusRequester.findFocusTargetNode$ui_release(FocusRequester.kt:275)
at androidx.compose.ui.focus.FocusRequester.requestFocus-3ESFkO8(FocusRequester.kt:82)
at androidx.compose.ui.focus.FocusRequester.requestFocus-3ESFkO8$default(FocusRequester.kt:82)
.....
The problem is that the focusRestorer try to focus the first item (firstItemFocusRequester) but this item is not on the screen.
The expected result is when I click on the last button, the button is deleted and the focus stay on the same line on the new last button.
Thank you for your investigation.
Description
Component used: TV
Version used:
Devices/Android versions reproduced on: All devices (tested with emulator and 2 market devices)
We are developing a tv app with jetpack compose and we are facing some crash issue. The last known issue happen with a LazyRow :
Here's a simple sample to reproduce the crash :
To reproduce the crash you can go to the last item of the first line and click on it. Then the button on the second line is immediately focused with the requestFocus. And after that, if you try to go up on the row, the system crash with this error :
IllegalStateException: Release should only be called once
Have you an idea how to avoid this crash ?