Prevent Keyboard from closing

后端 未结 2 1691
傲寒
傲寒 2021-01-14 13:45

I am struggling a little bit with this implementation. I\'m building my first Hello World! android(cordova) application that requires a keyboard to show always and avoid hid

2条回答
  •  遥遥无期
    2021-01-14 14:33

    Well, I think I came up with a different way, still not sure if this is how it should be handled.

    Add an event listener on Taps

    myApp.directive('detectGestures', function ($ionicGesture) {
      return {
        restrict: 'A',
        link: function (scope, elem, attrs) {
            var gestureType = attrs.gestureType;
            switch (gestureType) {
                case 'doubletap':
                    $ionicGesture.on('doubletap', scope.reportEvent, elem);
                    break;
        }}}
    });
    

    Then in My Controller, If keyboard is Visible close else Show

    $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);
             }
          };
    

    Let me know what you think.
    Thanks!

提交回复
热议问题