This is a react-native question for Android.
How can I handle the back button in Android when a TextInput is focused?
BackHandler.addEventListener('hardwareBackPress'. () => {})
does not catch any event if TextInput is focused. It automatically dismisses the keyboard.
(Actually what I am trying to achieve is to remove the cursor when Back Button is pressed and the keyboard is dismissed)
You can play with this expo snack to understand what I am talking about:
You'd handle it on the
TextInput
itself instead of using aBackHandler
. You can do this via theonKeyPress
propAlso it's important to note that on Android this event will only fire on the software keyboard, so if you're running on an emulator and use the backspace key on your computer's keyboard this will not work.