Skip to content

Commit

Permalink
optimize calls to updateRootLayoutSpecs
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mdvacca authored and facebook-github-bot committed Feb 24, 2019
1 parent daccb54 commit 2e42cc7
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public interface ReactRootViewEventListener {
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) {
Expand All @@ -116,6 +118,8 @@ private void init() {
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;

Expand Down Expand Up @@ -155,9 +159,11 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// 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);
Expand Down

0 comments on commit 2e42cc7

Please sign in to comment.