Jetpack Compose Focus Order with Talkback

Viewed 1151

Following the doc: https://developer.android.com/reference/kotlin/androidx/compose/ui/focus/package-summary#(androidx.compose.ui.Modifier).focusOrder(kotlin.Function1)

I want to have a custom focus order for a Column.

I've followed the doc and set different focus requesters to each item and specified the item to focus next, but it seems Talkback is ignoring the focus order of my elements.

Here's an example:

                val focusRequesters = remember { List(4) { FocusRequester() } }
                Column {
                    Text("Line 1",
                        Modifier
                            .focusOrder(focusRequesters[0]) {
                                next = focusRequesters[2]
                                down = focusRequesters[2]
                                right = focusRequesters[2]
                            }
                            .focusable())
                    Text("Line 2",
                        Modifier
                            .focusOrder(focusRequesters[1]) {
                                next = focusRequesters[0]
                                down = focusRequesters[0]
                                right = focusRequesters[0]
                            }
                            .focusable())
                    Text("Line 3",
                        Modifier
                            .focusOrder(focusRequesters[2]) {
                                next = focusRequesters[3]
                                down = focusRequesters[3]
                                right = focusRequesters[3]
                            }
                            .focusable())
                    Text("Line 4",
                        Modifier
                            .focusOrder(focusRequesters[3]) {
                                next = focusRequesters[1]
                                down = focusRequesters[1]
                                right = focusRequesters[1]
                            }
                            .focusable())
                }

Tried a combination of next, down, right and each alone but nothing seems to change the Accessibility traversal order.

1 Answers

The order of focus order will be taken into account if you change it with LocalFocusManager, something like this:

LocalFocusManager.current.moveFocus(FocusDirection.Next)

But it has nothing to do with accessibility. It seems that the android:accessibilityTraversalAfter counterpart is not yet available in Compose, follow this issue for details.

Related