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

Jasmin Fajkic

07/20/2022, 8:12 PM
I have on one screen text input and on back button press i would like to intercept it and run some function. Could not make it with BackHandler. Is there any chance to run custom function on hardware back button press?
c

Chris Fillmore

07/20/2022, 11:11 PM
That’s what BackHandler is for. What do you mean you couldn’t make it with BackHandler?
☝️ 1
j

Jasmin Fajkic

07/21/2022, 6:19 AM
I want to run function when keyboard is up and press back button to intercept it. But this function never runs.
c

Chris Fillmore

07/21/2022, 2:13 PM
Ah ok. When the keyboard is up, I think the back button becomes “keyboard dismiss” (this may be device vendor-specific), so no, BackHandler doesn’t work there, because there is no back button press. Depending on exactly what you want to do you might try `KeyboardActions`: https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/KeyboardActions or
onFocusChanged
modifier: https://developer.android.com/reference/kotlin/androidx/compose/ui/focus/package-summary#(androidx.compose.ui.Modifie[…]cusChanged(kotlin.Function1)
5 Views