I am trying to understand how focus works in Comps...
# compose
m
I am trying to understand how focus works in CompseUI. Say I have 4 Textfields and I want the user to enter values then press the action key and move to the next one. Is there any example of what parts of compose UI to use for this?
z
Haven’t tried this myself, but you could try playing with
Focusable
– maybe wrap each field in a
Focusable
? https://developer.android.com/reference/kotlin/androidx/ui/focus/package-summary#Focusable(androidx.ui.focus.FocusOperator,%20kotlin.Function1)
m
hmm yeah that's where i have started as well
Focusable takes Children and there is this FocusOperator, and the docs say it is for dealing with child focus in some parent..
z
Ah, there’s a simpler way. You can pass a string identifier to
TextField(focusIdentifier = "…")
. You can then pass that string to
FocusManager.requestFocusById()
. You can get the
FocusManager
by calling
FocusManagerAmbient.current
(must be done outside a callback).
m
hmm ok so i can use a FocusManager after all
thanks!
gonna try this out
l
This is actively being worked on. Please expect apis to change and current apis to be maybe a bit incomplete or buggy.
👍 1