Run callback when closing android keyboard

3

I have an app running with Cordova and Ionic. In this app I would like to perform an action on a certain controller when the keyboard completely closes.

Today I'm using cordova.plugins.Keyboard.close(); . The keyboard normally closes. However, I believe you do not have callback in this function.

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

    
asked by anonymous 04.08.2015 / 20:31

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);
     }
  };
    
04.08.2015 / 22:37
0

On pure Android, there is no listener that indicates the keyboard close event.

What many do is implement a ViewTreeObserver.OnGlobalLayoutListener. Here has a SOen post explaining.

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

  

Event to handle when the keyboard appears. Internally implements the above strategy

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

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

Event to handle when the keyboard disappears

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

function keyboardHideHandler(e){
    alert('Goodnight, sweet prince');
}
    
13.10.2017 / 13:00