Skip to content
This repository was archived by the owner on Apr 2, 2018. It is now read-only.

Commit 70479e0

Browse files
committed
add isVisible and ionic.hidekeyboard event to android
1 parent 46ba56a commit 70479e0

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/android/IonicKeyboard.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import org.apache.cordova.CordovaInterface;
44
import org.apache.cordova.CordovaPlugin;
55
import org.apache.cordova.CordovaWebView;
6-
import org.json.JSONException;
7-
import org.json.JSONObject;
86

97
import android.graphics.Rect;
108
import android.util.DisplayMetrics;
@@ -36,13 +34,20 @@ public void onGlobalLayout() {
3634
int heightDiff = rootView.getRootView().getHeight() - (r.bottom - r.top);
3735
if (heightDiff > 200 && heightDiff != previousHeightDiff) { // if more than 100 pixels, its probably a keyboard...
3836
int keyboardHeight = (int)(heightDiff / density);
39-
appView.sendJavascript("cordova.fireWindowEvent('ionic.showkeyboard', { 'keyboardHeight':" + Integer.toString(keyboardHeight)+"});");
37+
appView.sendJavascript("Keyboard.isVisible = true");
38+
appView.sendJavascript("cordova.fireWindowEvent('ionic.showkeyboard', { 'keyboardHeight':" + Integer.toString(keyboardHeight)+"});");
39+
}
40+
else if (heightDiff != previousHeightDiff && (previousHeightDiff - heightDiff) > 200){
41+
appView.sendJavascript("Keyboard.isVisible = false");
42+
appView.sendJavascript("cordova.fireWindowEvent('ionic.hidekeyboard')");
4043
}
4144
previousHeightDiff = heightDiff;
4245
}
4346
};
4447

4548
rootView.getViewTreeObserver().addOnGlobalLayoutListener(list);
4649
}
50+
51+
4752

4853
}

www/keyboard.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ Keyboard.disableScroll = function() {
4242
exec(null, null, "Keyboard", "disableScroll", []);
4343
};
4444

45+
Keyboard.isVisible = false;
46+
4547
module.exports = Keyboard;
4648

4749

0 commit comments

Comments
 (0)