Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-11943] Android: blur event not called when keyboard is hidden

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionDuplicate
Resolution Date2018-06-29T20:55:56.000+0000
Affected Version/sn/a
Fix Version/s2012 Sprint 26
ComponentsAndroid
Labelsn/a
ReporterDavide Cassenti
AssigneeUnknown
Created2012-12-04T10:06:03.000+0000
Updated2018-06-29T20:56:00.000+0000

Description

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();

Comments

  1. Allen Yeung 2012-12-11

    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.
  2. Leendert Gravendeel 2013-02-27

    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?
  3. Shyam Bhadauria 2013-05-10

    As per the comment by Allen, this is invalid bug.So closing it.
  4. Iker 2014-10-21

    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?
  5. Ingo Muschenetz 2014-11-10

    [~hpham] to investigate.
  6. Ping Wang 2014-12-03

    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.
  7. Ivan Skugor 2014-12-04

    "dismissKeyboard" would be very useful.
  8. ardy wongso 2015-04-21

    sorry, but i cant find dismissKeyboard in documentation, when this will be available?
  9. Ingo Muschenetz 2015-10-05

    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.
  10. Joshua Quick 2018-06-29

    The TextField/TextArea focus() and blur() functions are now working as expected on Android as of Titanium 7.0.0. The blur() 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 the blur() method is the only means of removing the focus.

JSON Source