mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Initialize RootView size to the display size
Summary: Inits RootView to display size for the early surface start experiment. Before that experiment, we always had the view measured before the surface was initialized, but here layout can sometimes happen before measure. Surface defaults use [0; Inf) for size constraints, potentially causing a crash in Yoga. This change avoids that by making a guess on default layout size with `displayMetrics` Changelog: [Internal] Reviewed By: feedthejim Differential Revision: D33190397 fbshipit-source-id: 3b1b84135a4980ef2fde4024ec84a448199e00b8
This commit is contained in:
committed by
Facebook GitHub Bot
parent
6568bc4bb2
commit
588320831f
@@ -19,6 +19,7 @@ import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.DisplayCutout;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
@@ -443,6 +444,11 @@ public class ReactRootView extends FrameLayout implements RootView, ReactRoot {
|
||||
// if in this experiment, we initialize the root earlier in startReactApplication
|
||||
// instead of waiting for the initial measure
|
||||
if (ReactFeatureFlags.enableEagerRootViewAttachment) {
|
||||
if (!mWasMeasured) {
|
||||
// Ideally, those values will be used by default, but we only update them here to scope
|
||||
// this change to `enableEagerRootViewAttachment` experiment.
|
||||
setSurfaceConstraintsToScreenSize();
|
||||
}
|
||||
attachToReactInstanceManager();
|
||||
}
|
||||
} finally {
|
||||
@@ -450,6 +456,14 @@ public class ReactRootView extends FrameLayout implements RootView, ReactRoot {
|
||||
}
|
||||
}
|
||||
|
||||
private void setSurfaceConstraintsToScreenSize() {
|
||||
DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics();
|
||||
mWidthMeasureSpec =
|
||||
MeasureSpec.makeMeasureSpec(displayMetrics.widthPixels, MeasureSpec.AT_MOST);
|
||||
mHeightMeasureSpec =
|
||||
MeasureSpec.makeMeasureSpec(displayMetrics.heightPixels, MeasureSpec.AT_MOST);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidthMeasureSpec() {
|
||||
return mWidthMeasureSpec;
|
||||
|
||||
Reference in New Issue
Block a user