mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-29 04:35:36 +08:00
Make keyboard detection more robust
Reviewed By: nspaun Differential Revision: D2905647 fb-gh-sync-id: 0bd5405f32a5e63c9f85178b4d1f777fe032f8d5
This commit is contained in:
committed by
facebook-github-bot-5
parent
4254e8a0a9
commit
5a109ae43b
@@ -389,11 +389,13 @@ public class ReactRootView extends SizeMonitoringFrameLayout implements RootView
|
|||||||
|
|
||||||
private class KeyboardListener implements ViewTreeObserver.OnGlobalLayoutListener {
|
private class KeyboardListener implements ViewTreeObserver.OnGlobalLayoutListener {
|
||||||
private final Rect mVisibleViewArea;
|
private final Rect mVisibleViewArea;
|
||||||
|
private final int mMinKeyboardHeightDetected;
|
||||||
|
|
||||||
private int mKeyboardHeight = 0;
|
private int mKeyboardHeight = 0;
|
||||||
|
|
||||||
/* package */ KeyboardListener() {
|
/* package */ KeyboardListener() {
|
||||||
mVisibleViewArea = new Rect();
|
mVisibleViewArea = new Rect();
|
||||||
|
mMinKeyboardHeightDetected = (int) PixelUtil.toPixelFromDIP(60);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -409,7 +411,7 @@ public class ReactRootView extends SizeMonitoringFrameLayout implements RootView
|
|||||||
getRootView().getWindowVisibleDisplayFrame(mVisibleViewArea);
|
getRootView().getWindowVisibleDisplayFrame(mVisibleViewArea);
|
||||||
final int heightDiff =
|
final int heightDiff =
|
||||||
DisplayMetricsHolder.getDisplayMetrics().heightPixels - mVisibleViewArea.bottom;
|
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
|
// keyboard is now showing, or the keyboard height has changed
|
||||||
mKeyboardHeight = heightDiff;
|
mKeyboardHeight = heightDiff;
|
||||||
WritableMap params = Arguments.createMap();
|
WritableMap params = Arguments.createMap();
|
||||||
@@ -420,9 +422,9 @@ public class ReactRootView extends SizeMonitoringFrameLayout implements RootView
|
|||||||
coordinates.putDouble("height", PixelUtil.toDIPFromPixel(mKeyboardHeight));
|
coordinates.putDouble("height", PixelUtil.toDIPFromPixel(mKeyboardHeight));
|
||||||
params.putMap("endCoordinates", coordinates);
|
params.putMap("endCoordinates", coordinates);
|
||||||
sendEvent("keyboardDidShow", params);
|
sendEvent("keyboardDidShow", params);
|
||||||
} else if (mKeyboardHeight != 0 && heightDiff == 0) {
|
} else if (mKeyboardHeight != 0 && heightDiff <= mMinKeyboardHeightDetected) {
|
||||||
// keyboard is now hidden
|
// keyboard is now hidden
|
||||||
mKeyboardHeight = heightDiff;
|
mKeyboardHeight = 0;
|
||||||
sendEvent("keyboardDidHide", null);
|
sendEvent("keyboardDidHide", null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user