From 5cdab30947fbdbbbc23a9180e6c222ce08c32be7 Mon Sep 17 00:00:00 2001 From: fabriziobertoglio1987 Date: Tue, 9 Feb 2021 12:03:12 +0100 Subject: [PATCH] compute correct Keyboard Height with Notch Without Notch - DisplayMetricsHolder.getWindowDisplayMetrics().heightPixels is 1794 - mVisibleViewArea.bottom is 1794 **With Notch** - DisplayMetricsHolder.getWindowDisplayMetrics().heightPixels is 1668 - mVisibleViewArea.bottom is 1794 Observations: - getWindowVisibleDisplayFrame().heightPixels returns correct height for devices with Notch - mVisibleViewArea.bottom does not take in consideration the notch (the value does not change) Solution: - Including the Notch Height in the Keyboard Height calculation Clear Explanation at https://github.com/facebook/react-native/issues/27089#issuecomment-775821333 https://github.com/facebook/react-native/blob/d79212120b7168015d3d0225ef372ed851a230fa/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java#L757-L758 --- .../src/main/java/com/facebook/react/ReactRootView.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java b/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java index 13074f8963e445..7f440be3e910e1 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java @@ -25,6 +25,7 @@ import android.view.ViewGroup; import android.view.ViewTreeObserver; import android.view.WindowManager; +import android.view.DisplayCutout; import android.widget.FrameLayout; import androidx.annotation.Nullable; import com.facebook.common.logging.FLog; @@ -766,8 +767,10 @@ public void onGlobalLayout() { private void checkForKeyboardEvents() { getRootView().getWindowVisibleDisplayFrame(mVisibleViewArea); + DisplayCutout displayCutout = getRootView().getRootWindowInsets().getDisplayCutout(); + int notchHeight = displayCutout == null ? 0 : displayCutout.getSafeInsetTop(); final int heightDiff = - DisplayMetricsHolder.getWindowDisplayMetrics().heightPixels - mVisibleViewArea.bottom; + DisplayMetricsHolder.getWindowDisplayMetrics().heightPixels - mVisibleViewArea.bottom + notchHeight; boolean isKeyboardShowingOrKeyboardHeightChanged = mKeyboardHeight != heightDiff && heightDiff > mMinKeyboardHeightDetected;