Skip to content

Commit b74d007

Browse files
andreicoman11bestander
authored andcommitted
Make keyboard detection more robust
Reviewed By: nspaun Differential Revision: D2905647 fb-gh-sync-id: 0bd5405f32a5e63c9f85178b4d1f777fe032f8d5
1 parent ff4ef2f commit b74d007

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,11 +389,13 @@ private KeyboardListener getKeyboardListener() {
389389

390390
private class KeyboardListener implements ViewTreeObserver.OnGlobalLayoutListener {
391391
private final Rect mVisibleViewArea;
392-
392+
private final int mMinKeyboardHeightDetected;
393+
393394
private int mKeyboardHeight = 0;
394395

395396
/* package */ KeyboardListener() {
396397
mVisibleViewArea = new Rect();
398+
mMinKeyboardHeightDetected = (int) PixelUtil.toPixelFromDIP(60);
397399
}
398400

399401
@Override
@@ -409,7 +411,7 @@ public void onGlobalLayout() {
409411
getRootView().getWindowVisibleDisplayFrame(mVisibleViewArea);
410412
final int heightDiff =
411413
DisplayMetricsHolder.getDisplayMetrics().heightPixels - mVisibleViewArea.bottom;
412-
if (mKeyboardHeight != heightDiff && heightDiff > 0) {
414+
if (mKeyboardHeight != heightDiff && heightDiff > mMinKeyboardHeightDetected) {
413415
// keyboard is now showing, or the keyboard height has changed
414416
mKeyboardHeight = heightDiff;
415417
WritableMap params = Arguments.createMap();
@@ -420,9 +422,9 @@ public void onGlobalLayout() {
420422
coordinates.putDouble("height", PixelUtil.toDIPFromPixel(mKeyboardHeight));
421423
params.putMap("endCoordinates", coordinates);
422424
sendEvent("keyboardDidShow", params);
423-
} else if (mKeyboardHeight != 0 && heightDiff == 0) {
425+
} else if (mKeyboardHeight != 0 && heightDiff <= mMinKeyboardHeightDetected) {
424426
// keyboard is now hidden
425-
mKeyboardHeight = heightDiff;
427+
mKeyboardHeight = 0;
426428
sendEvent("keyboardDidHide", null);
427429
}
428430
}

0 commit comments

Comments
 (0)