When I try to make TextField pre-focused using `on...
# compose
k
When I try to make TextField pre-focused using
onActive { focusRequester.requestFocus() }
keyboard doesn’t open, when focused manually, it works fine, what could be the issue? is there any other way of doing the same? also, I noticed
onActive { }
callback is getting deprecated. What should we use instead?
k
Maybe Ui not created when you request focus
k
What strategy you’d suggest for a TextField to get focus on UI created?
j
cc @Siyamed @Ralston Da Silva
r
I think this happens because the window isn't focused yet when onActive is run
You can use AmbientWindowInfo (or AmbientWindowManager) to find out when the Window is focused
I'll investigate and get back to you
j
Thanks @Ralston Da Silva! We should add this (easy/robust default focus routing) to our list of core use cases and make sure it's easy, because it's an important detail that every screen should think about.
r
Yes, I have a bug tracking this, we were trying to see how far we could go without providing API for default focus yet
In this case, it is not default focus that is off, it's just that the text fiels is focused, but the keyboard is not shown when the textfield is focused during onActive. I think for now we can add some logic in text field to show the keyboard if the text field is focused and the Window gains focus
👍 1
Anyway, I should reproduce this issue and verify if it is really a window focus issue. I want to investigate this before proposing a fix
I'm a little concerned about the case where a user intentionally dismisses the keyboard (and the text field is left focused) and then we re-show the keyboard when window focus changes.
k
Any updates on this? Should we put
requestFocus()
into a
LaunchedEffect
with
Unit
key?
r
Hi Kshitij, sorry for the delay. I think this is related to Window focus. I tried to reproduce this on an emulator but I can't reproduce the issue. Do you see this consistently or only sometimes? Which device are you using for testing?