I am trying to change the default focus from the top left to a different composable when the screen displays. I am attempting to get Talkback to read the text that is further down instead of the top-left button.
@Composable
fun Screen() {
val requester = FocusRequester()
Column {
Top()
Bottom(requester)
}
SideEffect {
requester.requestFocus()
}
}
@Composable
fun Top() {
Row{
Button(onClick = {}) {
Text(text = "top left")
}
Button(onClick = {}) {
Text(text = "top right")
}
}
@Composable
fun Bottom(requester: FocusRequester) {
Column {
Text(
text = "Text to read",
modifier = Modifier
.focusRequester(requester)
.focusable(true)
.focusTarget()
)
}
}
This code will work if a LaunchedEffect is used and the requestFocus call is delayed for 550. I suspect the requestFocus is called during the compose phase, and so there is nothing drawn to the screen yet for the request to "grab onto", like if it was called after the draw phase.