Problem description
When a TextArea is focused, and the user clicks the back button to hide the soft keyboard, the blur event is not fired. It is not also possible to use the 'android:back' event, as it is not fired when hiding the keyboard.
Steps to reproduce
- Use the following code to test the bug.
- Click on the black window to open a second one with a TextArea
- Click on it to show the keyboard
- Hit the back button: the 'blur' and 'android:back' events are not fired when keyboard is being hidden
// Create a window
var root = Ti.UI.createWindow({
backgroundColor : 'black',
modal: true
});
root.addEventListener('click', function() {
var win = Ti.UI.createWindow({
backgroundColor : 'white',
modal: true
});
var toolbar = Titanium.UI.createTextArea({
height: 37,
width: 200,
font: {fontSize:16,fontFamily:'ARIAL', fontWeight:'solid'},
color: '#000',
borderWidth: 1,
borderColor: '#828281',
borderRadius: 12,
suppressReturn: false,
scrollable: false
});
toolbar.addEventListener('blur', function() {
alert('blurrrred');
});
win.addEventListener('android:back', function() {
alert('baaaack');
});
win.add(toolbar);
win.open();
})
root.open();
The 'blur' event is attached to the textfield and not the soft keyboard itself, so it's expected that no blur event its fired. Similarly, the 'android:back' event is tied to the activity and not the soft keyboard. Native android does not expose a way for us to determine whether a soft keyboard is up or not. The API for inputmethodmanager is more generic in android, and we don't have anything specifically for soft keyboards.
I would very much appreciate it if this bug was fixed though. Have you already tried implementing onKeyPreIme in TiEditText (inside TiUIText), and checking for an incoming key code KeyEvent.KEYCODE_BACK?
As per the comment by Allen, this is invalid bug.So closing it.
Shyam Bhadauria: Please..., you cannot just close this topic like that, at least your development team should implement in the new feature to solve our problem! Since you said like that How the developer can believe in Titanium? How we solve our issue?
[~hpham] to investigate.
There is no native method to determine whether the keyboard is dismissed or not. But we can intercept key events to handle the BACK key specially, like this commit https://github.com/appcelerator/titanium_mobile/pull/6431/files . *Caveat*: The new event "dismissKeyboard" is only fired when the keyboard is dismissed by pressing the BACK key. If it is dismissed by pressing the DONE key, the event "return" will be fired instead.
"dismissKeyboard" would be very useful.
sorry, but i cant find dismissKeyboard in documentation, when this will be available?
As noted, there is no native method for this so we are uncomfortable taking a hack to support it. However, you can use the PR attached to accomplish it on your own SDK if you like.
The TextField/TextArea
focus()
andblur()
functions are now working as expected on Android as of Titanium 7.0.0. Theblur()
function will now dismiss the virtual keyboard and remove the focus from the field. Was resolved by ticket: [TIMOB-9680] Note that collapsing the virtual keyboard will NOT remove the focus from the TextField/TextArea. This is the correct native behavior on Android since the end-user can also enter text via physical keyboard as well (ex: bluetooth keyboard or slide-out keyboard). Switching the focus to another field or calling theblur()
method is the only means of removing the focus.