Skip to content

Commit

Permalink
Fix rootview layout when using flex
Browse files Browse the repository at this point in the history
Reviewed By: achen1

Differential Revision: D7753463

fbshipit-source-id: 5d2d70f9b5130ffe3b59a5364c589f437988ef37
  • Loading branch information
mdvacca authored and facebook-github-bot committed Apr 25, 2018
1 parent 409dbd2 commit a62aac5
Showing 1 changed file with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
import android.util.Log;
import android.view.View;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.GuardedRunnable;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.ReadableNativeMap;
import com.facebook.react.bridge.UIManager;
import com.facebook.react.common.ReactConstants;
import com.facebook.react.common.annotations.VisibleForTesting;
import com.facebook.react.modules.i18nmanager.I18nUtil;
import com.facebook.react.uimanager.DisplayMetricsHolder;
Expand All @@ -33,6 +35,7 @@
import com.facebook.react.uimanager.common.MeasureSpecProvider;
import com.facebook.react.uimanager.common.SizeMonitoringFrameLayout;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import javax.annotation.Nullable;

Expand Down Expand Up @@ -248,11 +251,12 @@ public void appendChildToSet(List<ReactShadowNode> childList, ReactShadowNode ch
childList.add(child);
}

public synchronized void completeRoot(int rootTag, List<ReactShadowNode> childList) {
if (DEBUG) {
Log.d(TAG, "completeRoot rootTag: " + rootTag + ", childList: " + childList);
}
public synchronized void completeRoot(int rootTag, @Nullable List<ReactShadowNode> childList) {
try {
childList = childList == null ? new LinkedList<ReactShadowNode>() : childList;
if (DEBUG) {
Log.d(TAG, "completeRoot rootTag: " + rootTag + ", childList: " + childList);
}
ReactShadowNode currentRootShadowNode = getRootNode(rootTag);
Assertions.assertNotNull(
currentRootShadowNode,
Expand Down Expand Up @@ -340,7 +344,7 @@ private void applyUpdatesRecursive(ReactShadowNode node, float absoluteX, float
@Override
public <T extends SizeMonitoringFrameLayout & MeasureSpecProvider> int addRootView(
final T rootView) {
int rootTag = ReactRootViewTagGenerator.getNextRootViewTag();
final int rootTag = ReactRootViewTagGenerator.getNextRootViewTag();
ThemedReactContext themedRootContext =
new ThemedReactContext(mReactApplicationContext, rootView.getContext());

Expand All @@ -350,11 +354,39 @@ public <T extends SizeMonitoringFrameLayout & MeasureSpecProvider> int addRootVi
int heightMeasureSpec = rootView.getHeightMeasureSpec();
updateRootView(rootShadowNode, widthMeasureSpec, heightMeasureSpec);

rootView.setOnSizeChangedListener(
new SizeMonitoringFrameLayout.OnSizeChangedListener() {
@Override
public void onSizeChanged(final int width, final int height, int oldW, int oldH) {
updateRootSize(rootTag, width, height);
}
});

mRootShadowNodeRegistry.registerNode(rootShadowNode);
mUIViewOperationQueue.addRootView(rootTag, rootView, themedRootContext);
return rootTag;
}

/**
* Updates the root view size and re-render the RN surface.
*
* //TODO: change synchronization to integrate with new #render loop.
*/
private synchronized void updateRootSize(int rootTag, int newWidth, int newHeight) {
ReactShadowNode rootNode = mRootShadowNodeRegistry.getNode(rootTag);
if (rootNode == null) {
Log.w(
ReactConstants.TAG,
"Tried to update size of non-existent tag: " + rootTag);
return;
}
int newWidthSpec = View.MeasureSpec.makeMeasureSpec(newWidth, View.MeasureSpec.EXACTLY);
int newHeightSpec = View.MeasureSpec.makeMeasureSpec(newHeight, View.MeasureSpec.EXACTLY);
updateRootView(rootNode, newWidthSpec, newHeightSpec);

completeRoot(rootTag, rootNode.getChildrenList());
}

public void removeRootView(int rootTag) {
mRootShadowNodeRegistry.removeNode(rootTag);
}
Expand Down

0 comments on commit a62aac5

Please sign in to comment.