mirror of
https://github.com/status-im/react-native.git
synced 2025-02-28 00:50:43 +00:00
Change cloning mechanism for mutableCopyWithNewChildren method
Reviewed By: achen1 Differential Revision: D7239873 fbshipit-source-id: d931e753c3a0b26d439eb450d62af93a672641f4
This commit is contained in:
parent
0930fef46d
commit
b43afcdde9
@ -177,7 +177,7 @@ public class FabricUIManager implements UIManager {
|
||||
private void assertReactShadowNodeCopy(ReactShadowNode source, ReactShadowNode target) {
|
||||
Assertions.assertCondition(source.getClass().equals(target.getClass()),
|
||||
"Found " + target.getClass() + " class when expecting: " + source.getClass() +
|
||||
". Check that " + source.getClass() + " implements the mutableCopy() method correctly.");
|
||||
". Check that " + source.getClass() + " implements the copy() method correctly.");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -74,11 +74,11 @@ public class LayoutShadowNode extends ReactShadowNodeImpl {
|
||||
|
||||
protected LayoutShadowNode(LayoutShadowNode node) {
|
||||
super(node);
|
||||
mTempYogaValue = new MutableYogaValue(node.mTempYogaValue);
|
||||
mTempYogaValue = new MutableYogaValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LayoutShadowNode mutableCopy() {
|
||||
protected LayoutShadowNode copy() {
|
||||
return new LayoutShadowNode(this);
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@ import com.facebook.yoga.YogaOverflow;
|
||||
import com.facebook.yoga.YogaPositionType;
|
||||
import com.facebook.yoga.YogaValue;
|
||||
import com.facebook.yoga.YogaWrap;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
@ -358,4 +359,10 @@ public interface ReactShadowNode<T extends ReactShadowNode> {
|
||||
boolean isMeasureDefined();
|
||||
|
||||
void dispose();
|
||||
|
||||
/**
|
||||
* @return an immutable {@link List<ReactShadowNode>} containing the children of this
|
||||
* {@link ReactShadowNode}.
|
||||
*/
|
||||
List<ReactShadowNode> getChildrenList();
|
||||
}
|
||||
|
@ -28,6 +28,8 @@ import com.facebook.yoga.YogaValue;
|
||||
import com.facebook.yoga.YogaWrap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
@ -96,7 +98,7 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
|
||||
private final Spacing mDefaultPadding = new Spacing(0);
|
||||
private final float[] mPadding = new float[Spacing.ALL + 1];
|
||||
private final boolean[] mPaddingIsPercent = new boolean[Spacing.ALL + 1];
|
||||
private final YogaNode mYogaNode;
|
||||
private YogaNode mYogaNode;
|
||||
|
||||
private @Nullable ReactStylesDiffMap mNewProps;
|
||||
|
||||
@ -120,8 +122,6 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
|
||||
mShouldNotifyOnLayout = original.mShouldNotifyOnLayout;
|
||||
mNodeUpdated = original.mNodeUpdated;
|
||||
mIsLayoutOnly = original.mIsLayoutOnly;
|
||||
mTotalNativeChildren = original.mTotalNativeChildren;
|
||||
mNativeParent = original.mNativeParent;
|
||||
mNativeParent = original.mNativeParent;
|
||||
mScreenX = original.mScreenX;
|
||||
mScreenY = original.mScreenY;
|
||||
@ -131,24 +131,38 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
|
||||
arraycopy(original.mPaddingIsPercent, 0, mPaddingIsPercent, 0, original.mPaddingIsPercent.length);
|
||||
mNewProps = null;
|
||||
mParent = null;
|
||||
mYogaNode = original.mYogaNode;
|
||||
// TODO: T26729293 clone YogaNode instead of reusing the same instance
|
||||
//mYogaNode = original.mYogaNode.clone();
|
||||
mNativeChildren = original.mNativeChildren == null ? null : new ArrayList<>(original.mNativeChildren);
|
||||
mChildren = original.mChildren == null ? null : new ArrayList<>(original.mChildren);
|
||||
mYogaNode.setData(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReactShadowNodeImpl mutableCopy() {
|
||||
/**
|
||||
* @return a copy of this object (no including copy of its children or the underlying yogaNode).
|
||||
*/
|
||||
protected ReactShadowNodeImpl copy() {
|
||||
return new ReactShadowNodeImpl(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReactShadowNodeImpl mutableCopy() {
|
||||
ReactShadowNodeImpl copy = copy();
|
||||
copy.mYogaNode = mYogaNode;
|
||||
// TODO: T26729293 clone YogaNode instead of reusing the same instance
|
||||
//mYogaNode = original.mYogaNode.clone();
|
||||
copy.mNativeChildren = mNativeChildren == null ? null : new ArrayList<>(mNativeChildren);
|
||||
copy.mTotalNativeChildren = mTotalNativeChildren;
|
||||
copy.mChildren = mChildren == null ? null : new ArrayList<>(mChildren);
|
||||
copy.mYogaNode.setData(this);
|
||||
return copy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReactShadowNodeImpl mutableCopyWithNewChildren() {
|
||||
ReactShadowNodeImpl copy = mutableCopy();
|
||||
ReactShadowNodeImpl copy = copy();
|
||||
copy.mYogaNode = mYogaNode;
|
||||
// TODO: T26729293 clone YogaNode instead of reusing the same instance
|
||||
//mYogaNode = original.mYogaNode.cloneWithNewChildren();
|
||||
copy.mNativeChildren = null;
|
||||
copy.mChildren = null;
|
||||
copy.mTotalNativeChildren = 0;
|
||||
copy.mYogaNode.setData(this);
|
||||
return copy;
|
||||
}
|
||||
|
||||
@ -253,10 +267,6 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
|
||||
|
||||
@Override
|
||||
public void addChildAt(ReactShadowNodeImpl child, int i) {
|
||||
if (child.getParent() != null) {
|
||||
throw new IllegalViewOperationException(
|
||||
"Tried to add child that already has a parent! Remove it from its parent first.");
|
||||
}
|
||||
if (mChildren == null) {
|
||||
mChildren = new ArrayList<>(4);
|
||||
}
|
||||
@ -1056,4 +1066,10 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
|
||||
YogaNodePool.get().release(mYogaNode);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<ReactShadowNode> getChildrenList() {
|
||||
return mChildren == null ? null : Collections.<ReactShadowNode>unmodifiableList(mChildren);
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ public class ARTGroupShadowNode extends ARTVirtualNode {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReactShadowNodeImpl mutableCopy() {
|
||||
protected ReactShadowNodeImpl copy() {
|
||||
return new ARTGroupShadowNode(this);
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ public class ARTShapeShadowNode extends ARTVirtualNode {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ARTShapeShadowNode mutableCopy() {
|
||||
protected ARTShapeShadowNode copy() {
|
||||
return new ARTShapeShadowNode(this);
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ public class ARTTextShadowNode extends ARTShapeShadowNode {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ARTShapeShadowNode mutableCopy() {
|
||||
protected ARTShapeShadowNode copy() {
|
||||
return new ARTTextShadowNode(this);
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ class ModalHostShadowNode extends LayoutShadowNode {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModalHostShadowNode mutableCopy() {
|
||||
protected ModalHostShadowNode copy() {
|
||||
return new ModalHostShadowNode(this);
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ public class ProgressBarShadowNode extends LayoutShadowNode implements YogaMeasu
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProgressBarShadowNode mutableCopy() {
|
||||
protected ProgressBarShadowNode copy() {
|
||||
return new ProgressBarShadowNode(this);
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ public class ReactSliderManager extends SimpleViewManager<ReactSlider> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReactSliderShadowNode mutableCopy() {
|
||||
protected ReactSliderShadowNode copy() {
|
||||
return new ReactSliderShadowNode(this);
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ public class ReactSwitchManager extends SimpleViewManager<ReactSwitch> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReactSwitchShadowNode mutableCopy() {
|
||||
protected ReactSwitchShadowNode copy() {
|
||||
return new ReactSwitchShadowNode(this);
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ public class ReactRawTextShadowNode extends ReactShadowNodeImpl {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReactShadowNodeImpl mutableCopy() {
|
||||
protected ReactShadowNodeImpl copy() {
|
||||
return new ReactRawTextShadowNode(this);
|
||||
}
|
||||
|
||||
|
@ -154,7 +154,7 @@ public class ReactTextShadowNode extends ReactBaseTextShadowNode {
|
||||
}
|
||||
|
||||
@Override
|
||||
public LayoutShadowNode mutableCopy() {
|
||||
protected LayoutShadowNode copy() {
|
||||
return new ReactTextShadowNode(this);
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ public class ReactVirtualTextShadowNode extends ReactBaseTextShadowNode {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReactVirtualTextShadowNode mutableCopy() {
|
||||
protected ReactVirtualTextShadowNode copy() {
|
||||
return new ReactVirtualTextShadowNode(this);
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ public class FrescoBasedReactTextInlineImageShadowNode extends ReactTextInlineIm
|
||||
}
|
||||
|
||||
@Override
|
||||
public FrescoBasedReactTextInlineImageShadowNode mutableCopy() {
|
||||
protected FrescoBasedReactTextInlineImageShadowNode copy() {
|
||||
return new FrescoBasedReactTextInlineImageShadowNode(this);
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ public class ReactTextInputShadowNode extends ReactBaseTextShadowNode
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReactTextInputShadowNode mutableCopy() {
|
||||
protected ReactTextInputShadowNode copy() {
|
||||
return new ReactTextInputShadowNode(this);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user