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

Chuck Stein

08/12/2021, 12:48 AM
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.)
c

Colton Idle

08/12/2021, 1:02 AM
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)
👀
🙌 1
c

Chuck Stein

08/12/2021, 4:35 PM
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).
c

Colton Idle

08/12/2021, 4:49 PM
Might be worth filing a bug about it?
2 Views