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

allan.conda

03/02/2021, 9:11 AM
Has the default behaviors of ImeActions in Text worked for anyone? Seems it has never worked since compose-dev. Still not working in beta01
specifically, ImeAction.Next isn’t going to the next focusable
r

Rahul Sainani

03/02/2021, 9:52 AM
Hey I think you need to request focus from the next text field in onNext of the first text field
Copy code
val lastNameFocusRequest = remember { FocusRequester() }
                    val focusManager = LocalFocusManager.current

                    TextField(
                        ..
                        keyboardOptions = KeyboardOptions.Default.copy(imeAction = ImeAction.Next),
                        keyboardActions = KeyboardActions(onNext = { lastNameFocusRequest.requestFocus() }),
                        modifier = Modifier.weight(0.33f)
                    )
                    TextField(
                        ...
                        keyboardOptions = KeyboardOptions.Default.copy(imeAction = ImeAction.Done),
                        keyboardActions = KeyboardActions(
                            onDone = {
                                focusManager.clearFocus()
                                currentPage = getNextState(currentPage)
                            }
                        ),
                        modifier = Modifier
                            .weight(0.33f)
                            .focusRequester(lastNameFocusRequest)
                    )
a

allan.conda

03/02/2021, 9:53 AM
Yeah, I do that. But I shouldn’t have to I think. See this documentation in KeyboardActions
thanks for the example btw!
🙌 1
r

Rahul Sainani

03/02/2021, 9:54 AM
Ooh! It didn't work for me without this. How does the system know about the focus traversal order though? Does the parent need to communicate to the system somehow?
a

allan.conda

03/02/2021, 9:56 AM
I can only guess that probably compose is able to traverse through the composable hierarchy and find out the next focus. But I think it may not be implemented yet…
j

JulianK

03/02/2021, 10:10 AM
As far as i understand, automatically focusing the next textfield is not expected behaviour for now, see https://issuetracker.google.com/issues/165676636
a

allan.conda

03/02/2021, 10:16 AM
status is won’t fix, not reproducible. 🤔
but good find, it might be a regression
z

Zach Klippenstein (he/him) [MOD]

03/02/2021, 4:26 PM
I would just file a new bug, link to the old one if you think it’s a regression.
Tracker link is in the channel topic
s

Samir Basnet

03/15/2021, 8:22 AM
Is there any update on this?