Chuck Stein

    Chuck Stein

    1 year ago
    Is there any way to add a callback for when the user closes the software keyboard in Compose? I want to unfocus my TextField when the user closes the keyboard, so that they don't have to press the back button 3 times to exit a search query. (Currently it's once to close the keyboard, a second time to unfocus the TextField, and then only the third time does my custom BackHandler get called, to exit the search page.)
    Colton Idle

    Colton Idle

    1 year ago
    Compose 1.1.0-alpha01 fixes this I believe (or 1.0.1) as I had the same issue and it resolved itself once I updated!
    https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.1.0-alpha01
    TextField now clears selection when back button is pressed, which matches Android EditText behavior. (I3ca16b/174173645)
    👀
    Chuck Stein

    Chuck Stein

    1 year ago
    Thanks! After updating, the TextField no longer consumes the back press event when focused and not showing the keyboard, so my custom BackHandler is now called to exit the search page. Curiously, this behavior is not exactly what is described in that release note, and it seems like there is no way to achieve my original goal of unfocusing the TextField when the keyboard is dismissed (I know this is at least possible with the View system because Spotify's search does it).
    Colton Idle

    Colton Idle

    1 year ago
    Might be worth filing a bug about it?