https://kotlinlang.org logo
#compose
Title
# compose
m

Matthewdhowell

03/12/2020, 10:47 PM
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

Zach Klippenstein (he/him) [MOD]

03/12/2020, 11:43 PM
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

Matthewdhowell

03/12/2020, 11:44 PM
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

Zach Klippenstein (he/him) [MOD]

03/13/2020, 3:10 AM
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

Matthewdhowell

03/13/2020, 3:24 AM
hmm ok so i can use a FocusManager after all
thanks!
gonna try this out
l

Leland Richardson [G]

03/13/2020, 6:44 AM
This is actively being worked on. Please expect apis to change and current apis to be maybe a bit incomplete or buggy.
👍 1