optimize calls to updateRootLayoutSpecs

Summary: This diff changes the onMeasure method of the RootView to optimize the amount of times we call updateRootLayoutSpecs in Fabric

Reviewed By: shergin

Differential Revision: D14198155

fbshipit-source-id: ff2deee04540899c25d4e38b0bd93333f74c6ace
This commit is contained in:
David Vacca 2019-02-24 11:55:50 -08:00 коммит произвёл Facebook Github Bot
Родитель daccb54353
Коммит 2e42cc7652
1 изменённых файлов: 7 добавлений и 1 удалений

Просмотреть файл

@ -91,6 +91,8 @@ public class ReactRootView extends FrameLayout implements RootView {
private boolean mWasMeasured = false;
private int mWidthMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
private int mHeightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
private int mLastWidth = 0;
private int mLastHeight = 0;
private @UIManagerType int mUIManagerType = DEFAULT;
public ReactRootView(Context context) {
@ -116,6 +118,8 @@ public class ReactRootView extends FrameLayout implements RootView {
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "ReactRootView.onMeasure");
try {
boolean measureSpecsUpdated = widthMeasureSpec != mWidthMeasureSpec ||
heightMeasureSpec != mHeightMeasureSpec;
mWidthMeasureSpec = widthMeasureSpec;
mHeightMeasureSpec = heightMeasureSpec;
@ -155,9 +159,11 @@ public class ReactRootView extends FrameLayout implements RootView {
// Check if we were waiting for onMeasure to attach the root view.
if (mReactInstanceManager != null && !mIsAttachedToInstance) {
attachToReactInstanceManager();
} else {
} else if (measureSpecsUpdated || mLastWidth != width || mLastHeight != height) {
updateRootLayoutSpecs(mWidthMeasureSpec, mHeightMeasureSpec);
}
mLastWidth = width;
mLastHeight = height;
} finally {
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);