Skip to content

Commit

Permalink
compute correct Keyboard Height with Notch
Browse files Browse the repository at this point in the history
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 facebook#27089 (comment)

https://github.com/facebook/react-native/blob/d79212120b7168015d3d0225ef372ed851a230fa/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java#L757-L758
  • Loading branch information
fabOnReact authored and cortinico committed Sep 28, 2021
1 parent 3516090 commit 5cdab30
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 5cdab30

Please sign in to comment.