Thread
#compose
    k

    Kshitij Patil

    1 year ago
    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?
    Karthick

    Karthick

    1 year ago
    Maybe Ui not created when you request focus
    k

    Kshitij Patil

    1 year ago
    What strategy you’d suggest for a TextField to get focus on UI created?
    I searched a lot but didn’t find any example showing how to have particular
    TextField
    pre-focused when a Composable is rendered, is this not recommended as per the best practices?
    jim

    jim

    1 year ago
    cc @Siyamed @Ralston Da Silva
    r

    Ralston Da Silva

    1 year ago
    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
    jim

    jim

    1 year ago
    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

    Ralston Da Silva

    1 year ago
    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
    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

    Kshitij Patil

    1 year ago
    Any updates on this? Should we put
    requestFocus()
    into a
    LaunchedEffect
    with
    Unit
    key?
    r

    Ralston Da Silva

    1 year ago
    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?