Skip to content

Commit

Permalink
Fix appendChild
Browse files Browse the repository at this point in the history
Reviewed By: mdvacca

Differential Revision: D7128443

fbshipit-source-id: 4eedea4df2b636eb9589cbe5e84c5c6a8aa33539
  • Loading branch information
ayc1 authored and facebook-github-bot committed Mar 2, 2018
1 parent 6404529 commit 78b3065
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.facebook.react.uimanager.ReactStylesDiffMap;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.UIViewOperationQueue;
import com.facebook.react.uimanager.ViewAtIndex;
import com.facebook.react.uimanager.ViewManager;
import com.facebook.react.uimanager.ViewManagerRegistry;
import com.facebook.react.uimanager.common.MeasureSpecProvider;
Expand Down Expand Up @@ -179,8 +180,16 @@ private void assertReactShadowNodeCopy(ReactShadowNode source, ReactShadowNode t
@Nullable
public void appendChild(ReactShadowNode parent, ReactShadowNode child) {
try {
parent.addChildAt(child, parent.getChildCount());
addChild(parent.getReactTag(), child.getReactTag());
int childIndex = parent.getChildCount();
parent.addChildAt(child, childIndex);
ViewAtIndex[] viewsToAdd =
new ViewAtIndex[]{new ViewAtIndex(child.getReactTag(), childIndex)};
mUIViewOperationQueue.enqueueManageChildren(
parent.getReactTag(),
null,
viewsToAdd,
null
);
} catch (Exception e) {
handleException(parent.getThemedContext(), e);
}
Expand Down Expand Up @@ -209,8 +218,7 @@ public void completeRoot(int rootTag, List<ReactShadowNode> childList) {
"Root view with tag " + rootTag + " must be added before completeRoot is called");
for (int i = 0; i < childList.size(); i++) {
ReactShadowNode child = childList.get(i);
rootNode.addChildAt(child, i);
addChild(rootTag, child.getReactTag());
appendChild(rootNode, child);
}

calculateRootLayout(rootNode);
Expand All @@ -222,15 +230,6 @@ public void completeRoot(int rootTag, List<ReactShadowNode> childList) {
}
}

private void addChild(int parent, int child) {
JavaOnlyArray childrenTags = new JavaOnlyArray();
childrenTags.pushInt(child);
mUIViewOperationQueue.enqueueSetChildren(
parent,
childrenTags
);
}

private void calculateRootLayout(ReactShadowNode cssRoot) {
cssRoot.calculateLayout();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Data structure that couples view tag to it's index in parent view. Used for managing children
* operation.
*/
/* package */ class ViewAtIndex {
public class ViewAtIndex {
public static Comparator<ViewAtIndex> COMPARATOR = new Comparator<ViewAtIndex>() {
@Override
public int compare(ViewAtIndex lhs, ViewAtIndex rhs) {
Expand Down

0 comments on commit 78b3065

Please sign in to comment.