Make keyboard detection more robust

Reviewed By: nspaun

Differential Revision: D2905647

fb-gh-sync-id: 0bd5405f32a5e63c9f85178b4d1f777fe032f8d5
This commit is contained in:
Andrei Coman 2016-02-08 11:45:32 -08:00 committed by facebook-github-bot-5
parent 4254e8a0a9
commit 5a109ae43b
1 changed files with 6 additions and 4 deletions

View File

@ -389,11 +389,13 @@ public class ReactRootView extends SizeMonitoringFrameLayout implements RootView
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
@ -409,7 +411,7 @@ public class ReactRootView extends SizeMonitoringFrameLayout implements RootView
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();
@ -420,9 +422,9 @@ public class ReactRootView extends SizeMonitoringFrameLayout implements RootView
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);
}
}