-
Notifications
You must be signed in to change notification settings - Fork 374
Open
Description
When you override onKeyPresser with "handleDPadKeyEvents" and you have "focusRestoter" pressing dPag up (triggering on up) results in focusing the first item. If you remove the focus restorer this issue is not reproduced.
Example code:
@Composable
fun Screen() {
val focusManager = LocalFocusManager.current
LazyColumn {
item {
repeat(10){
MyLazyRow(focusManager)
}
}
}
}
@Composable
fun MyLazyRow(focusManager: FocusManager) {
val (lazyRow, firstItem) = remember { FocusRequester.createRefs() }
LazyRow(
horizontalArrangement = Arrangement.spacedBy(20.dp),
modifier = Modifier
.focusRequester(lazyRow)
.focusRestorer {
firstItem
},
) {
repeat(10) { index ->
item {
val itemModifier = if (index == 0) {
Modifier.focusRequester(firstItem)
} else {
Modifier
}
OutlinedButton(
onClick = {
focusRequester.saveFocusedChild()
println("Button clicked")
},
content = {
Text("My Button $index")
},
modifier = itemModifier
.handleDPadKeyEvents(onUp = {
focusManager.moveFocus(FocusDirection.Up)
}),
border = ButtonDefaults.border(
border = Border(
border = BorderStroke(
width = 1.dp,
color = Color.Red
),
shape = RoundedCornerShape(6.dp)
),
focusedBorder = Border(
border = BorderStroke(width = 10.dp, color = Color.Green),
shape = RoundedCornerShape(6.dp)
),
disabledBorder = Border(
BorderStroke(
width = 1.dp,
color = colors.onBackground.copy(0.4f)
)
),
focusedDisabledBorder = Border(
BorderStroke(
width = 1.dp,
color = colors.onBackground.copy(0.4f)
)
)
),
)
}
}
}
}
Metadata
Metadata
Assignees
Labels
No labels