Run callback on close android keyboard

Asked

Viewed 384 times

2

I have a app running with Cordova and Ionic. In this app i would like to effect an action in particular controller when the keyboard closes completely.

Today I’m using cordova.plugins.Keyboard.close();. Currently the keyboard closes normally. However, I believe it does not have a callback in that capacity.

What is the way when the keyboard closes completely, only then run something?

2 answers

2


You can try something like this:

$scope.reportEvent = function (event) {
  if (event.type == 'doubletap') {
      $timeout(function () {
          if (window.cordova && window.cordova.plugins.Keyboard) {
              if(cordova.plugins.Keyboard.isVisible){
                  window.cordova.plugins.Keyboard.close();
              } else {
                  window.cordova.plugins.Keyboard.show();
              }

          }
       }, 500);
     }
  };

0

On pure Android, there is no Switch indicating the keyboard closing event.

What many do is implement a Viewtreeobserver.Ongloballayoutlistener. Here has a post from Soen explaining.

In Cordova, I found that in the plugin com.ionic.Keyboard, it has the following events (link):

Event to handle when keyboard appears. Internally implements above strategy

window.addEventListener('native.keyboardshow', keyboardShowHandler);

function keyboardShowHandler(e){
    alert('Keyboard height is: ' + e.keyboardHeight);
}

Event to treat when keyboard disappears

window.addEventListener('native.keyboardhide', keyboardHideHandler);

function keyboardHideHandler(e){
    alert('Goodnight, sweet prince');
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.