Skip to content

Commit 7f07602

Browse files
committed
Inline a logic similar to DeviceModuleInfo getWindowDisplayMetrics
1 parent c3aa109 commit 7f07602

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
import android.widget.FrameLayout;
3939
import androidx.annotation.Nullable;
4040
import androidx.annotation.RequiresApi;
41+
import androidx.core.view.ViewCompat;
42+
import androidx.core.view.WindowInsetsCompat;
4143
import androidx.window.layout.WindowMetricsCalculator;
4244
import com.facebook.common.logging.FLog;
4345
import com.facebook.infer.annotation.Assertions;
@@ -1024,13 +1026,25 @@ private void checkForKeyboardEventsLegacy() {
10241026
}
10251027
}
10261028

1029+
int heightPixels = getContext().getResources().getDisplayMetrics().heightPixels;
10271030
final ReactContext reactContext = getCurrentReactContext();
10281031
final Activity activity = reactContext != null ? reactContext.getCurrentActivity() : null;
10291032

1030-
final int heightPixels = activity != null && WindowUtilKt.isEdgeToEdgeFeatureFlagOn()
1031-
? WindowMetricsCalculator.getOrCreate()
1032-
.computeCurrentWindowMetrics(activity).getBounds().height()
1033-
: getContext().getResources().getDisplayMetrics().heightPixels;
1033+
if (activity != null) {
1034+
heightPixels = WindowMetricsCalculator.getOrCreate()
1035+
.computeCurrentWindowMetrics(activity).getBounds().height();
1036+
1037+
if (!WindowUtilKt.isEdgeToEdgeFeatureFlagOn()) {
1038+
WindowInsetsCompat rootWindowInsets =
1039+
ViewCompat.getRootWindowInsets(activity.getWindow().getDecorView());
1040+
1041+
if (rootWindowInsets != null) {
1042+
androidx.core.graphics.Insets insets =
1043+
rootWindowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
1044+
heightPixels -= (insets.top + insets.bottom);
1045+
}
1046+
}
1047+
}
10341048

10351049
final int heightDiff = heightPixels - mVisibleViewArea.bottom + notchHeight;
10361050

0 commit comments

Comments
 (0)