how do i get out of a focusGroup() once an element...
# compose
a
how do i get out of a focusGroup() once an element is focused? the documentation explains how to specify order but when you do that, you can't leave the group https://developer.android.com/develop/ui/compose/touch-input/focus/change-focus-behavior#provide-coherent
More specifically, how do i mark an element that is the last item in the list, so that when i press Tab on it it moves out of the group? If I specify 'Default' to it it will move to the next 'logical' one which might be an other focus target in the group. this causes a infinite loop
h
that sounds like a bug. FocusGroup isn't about capturing the focus altogether, it should serve as a priority indicator. In your case, how does the UI look like when you reach the last item in your
focusGroup
? Where is the next supposed focusable item that is outside the
focusGroup
?
t
There's a couple of issues about focus next item detection. Like https://issuetracker.google.com/issues/367440163 that can lead to this when the focus group is large and the item below is small. Calculation is even different for next and previous.
a
@Halil Ozercan My bad. I linked to the wrong thing. Here is the docs I meant to link: https://developer.android.com/develop/ui/compose/touch-input/focus/change-focus-traversal-order Here is a slightly different code from the docs. If the last item is not the 'logical' last item in the layout, then there is no way to exit the group (i think)
???
<- not sure what to put there so that i can move to 'outside' after, without passing a ref to 'outside'. PS: I can't put a ref to outside because im working on a library. the inner row is my library component and i can't control the outside
Copy code
Row {
            val (first, second, third) = remember { FocusRequester.createRefs() }

            Row {
                Button(
                    {},
                    modifier = Modifier
                        .focusRequester(first)
                        .focusProperties { next = second }
                ) {
                    Text("First field")
                }
                Button(
                    {},
                    modifier = Modifier
                        .focusRequester(third)
                        .focusProperties { next = ??? }
                ) {
                    Text("Third field")
                }
                Button(
                    {},
                    modifier = Modifier
                        .focusRequester(second)
                        .focusProperties { next = first }
                ) {
                    Text("Last field")
                }

            }

            Button(onClick = {}) {
                Text("Outside")
            }
        }