Skip to content

Commit

Permalink
Make keyboard detection more robust
Browse files Browse the repository at this point in the history
Reviewed By: nspaun

Differential Revision: D2905647

fb-gh-sync-id: 0bd5405f32a5e63c9f85178b4d1f777fe032f8d5
  • Loading branch information
andreicoman11 authored and pglotov committed Mar 15, 2016
1 parent 4d63caf commit 44cc812
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java
Original file line number Diff line number Diff line change
Expand Up @@ -389,11 +389,13 @@ private KeyboardListener getKeyboardListener() {

private class KeyboardListener implements ViewTreeObserver.OnGlobalLayoutListener {
private final Rect mVisibleViewArea;

private final int mMinKeyboardHeightDetected;

private int mKeyboardHeight = 0;

/* package */ KeyboardListener() {
mVisibleViewArea = new Rect();
mMinKeyboardHeightDetected = (int) PixelUtil.toPixelFromDIP(60);
}

@Override
Expand All @@ -409,7 +411,7 @@ public void onGlobalLayout() {
getRootView().getWindowVisibleDisplayFrame(mVisibleViewArea);
final int heightDiff =
DisplayMetricsHolder.getDisplayMetrics().heightPixels - mVisibleViewArea.bottom;
if (mKeyboardHeight != heightDiff && heightDiff > 0) {
if (mKeyboardHeight != heightDiff && heightDiff > mMinKeyboardHeightDetected) {
// keyboard is now showing, or the keyboard height has changed
mKeyboardHeight = heightDiff;
WritableMap params = Arguments.createMap();
Expand All @@ -420,9 +422,9 @@ public void onGlobalLayout() {
coordinates.putDouble("height", PixelUtil.toDIPFromPixel(mKeyboardHeight));
params.putMap("endCoordinates", coordinates);
sendEvent("keyboardDidShow", params);
} else if (mKeyboardHeight != 0 && heightDiff == 0) {
} else if (mKeyboardHeight != 0 && heightDiff <= mMinKeyboardHeightDetected) {
// keyboard is now hidden
mKeyboardHeight = heightDiff;
mKeyboardHeight = 0;
sendEvent("keyboardDidHide", null);
}
}
Expand Down

0 comments on commit 44cc812

Please sign in to comment.