Do you guys have any idea on how to intercept back...
# compose
l
Do you guys have any idea on how to intercept back press when user’s editing text and keyboard is being shown? Can’t find a way to intercept the back press, the keyboard just gets hidden.
OnBackPressedDispatcher
doesn’t seem to help
i
The IME closing is the expected behavior of the system back button when it is open - that window is the one who gets the back button, not your Activity
l
Yeah, but what about doing some other actions on top of the default behaviour, eg. Droping focus?
r
We don't have a way to do this currently. The app doesn't know if the keyboard is showing or not. In addition to the back key press, you could end up in this state in a number of ways: 1. The user manually hides the keyboard by tapping on ▼ 2. The user connects a hardware keyboard to the system which dismisses the soft keyboard I would like to understand the usecase better. Why do you want to clear focus when the user dismisses the keyboard? We don't have a compose API to do this, but there is a way to check if the keyboard is visible or not, but this is only available after R:
LocalView.current.rootWindowInsets?.isVisible(WindowInsets.Type.ime())
You could check this periodically and then call
LocalFocusManager.current.clearFocus()