Make Spacing cloneable
Reviewed By: achen1 Differential Revision: D7626745 fbshipit-source-id: ca6070a99d561ee5d5dd27456116dd2de75d2bf3
This commit is contained in:
parent
49655c6eb3
commit
7e824867ca
|
@ -106,7 +106,7 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
|
|||
private int mScreenY;
|
||||
private int mScreenWidth;
|
||||
private int mScreenHeight;
|
||||
private final Spacing mDefaultPadding = new Spacing(0);
|
||||
private final Spacing mDefaultPadding;
|
||||
private final float[] mPadding = new float[Spacing.ALL + 1];
|
||||
private final boolean[] mPaddingIsPercent = new boolean[Spacing.ALL + 1];
|
||||
private YogaNode mYogaNode;
|
||||
|
@ -115,6 +115,7 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
|
|||
private @Nullable ReactStylesDiffMap mNewProps;
|
||||
|
||||
public ReactShadowNodeImpl() {
|
||||
mDefaultPadding = new Spacing(0);
|
||||
if (!isVirtual()) {
|
||||
YogaNode node = YogaNodePool.get().acquire();
|
||||
mYogaNode = node == null ? new YogaNode(sYogaConfig) : node;
|
||||
|
@ -133,6 +134,7 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
|
|||
mShouldNotifyOnLayout = original.mShouldNotifyOnLayout;
|
||||
mIsLayoutOnly = original.mIsLayoutOnly;
|
||||
mNativeParent = original.mNativeParent;
|
||||
mDefaultPadding = new Spacing(original.mDefaultPadding);
|
||||
// Cloned nodes should be always updated.
|
||||
mNodeUpdated = true;
|
||||
// "cached" screen coordinates are not cloned because FabricJS not always clone the last
|
||||
|
|
|
@ -68,9 +68,9 @@ public class Spacing {
|
|||
256, /*ALL*/
|
||||
};
|
||||
|
||||
private final float[] mSpacing = newFullSpacingArray();
|
||||
private final float[] mSpacing;
|
||||
private int mValueFlags = 0;
|
||||
private float mDefaultValue;
|
||||
private final float mDefaultValue;
|
||||
private boolean mHasAliasesSet;
|
||||
|
||||
public Spacing() {
|
||||
|
@ -79,6 +79,14 @@ public class Spacing {
|
|||
|
||||
public Spacing(float defaultValue) {
|
||||
mDefaultValue = defaultValue;
|
||||
mSpacing = newFullSpacingArray();
|
||||
}
|
||||
|
||||
public Spacing(Spacing original) {
|
||||
mDefaultValue = original.mDefaultValue;
|
||||
mSpacing = Arrays.copyOf(original.mSpacing, original.mSpacing.length);
|
||||
mValueFlags = original.mValueFlags;
|
||||
mHasAliasesSet = original.mHasAliasesSet;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -29,6 +29,7 @@ import java.util.Arrays;
|
|||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import org.fest.assertions.data.Offset;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -113,6 +114,18 @@ public class FabricUIManagerTest {
|
|||
assertThat(clonedNode.getChildAt(0)).isEqualTo(child);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultSpacingCloning() {
|
||||
ReactShadowNode node = createViewNode();
|
||||
node.setDefaultPadding(Spacing.LEFT, 10);
|
||||
|
||||
ReactShadowNode clonedNode = mFabricUIManager.cloneNode(node);
|
||||
|
||||
node.setDefaultPadding(Spacing.LEFT, 20);
|
||||
assertThat(clonedNode.getStylePadding(Spacing.LEFT).value).isEqualTo(10f, Offset.offset(0.01f));
|
||||
assertThat(node.getStylePadding(Spacing.LEFT).value).isEqualTo(20f, Offset.offset(0.01f));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloneVirtualNode() {
|
||||
ReactRawTextShadowNode node = new ReactRawTextShadowNode();
|
||||
|
|
Loading…
Reference in New Issue