diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNodeImpl.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNodeImpl.java index d0eb127f6e29e4..a8118b1841d0b8 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNodeImpl.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNodeImpl.java @@ -106,7 +106,7 @@ public YogaNode cloneNode(YogaNode oldYogaNode, 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 YogaNode cloneNode(YogaNode oldYogaNode, 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 @@ protected ReactShadowNodeImpl(ReactShadowNodeImpl original) { 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 diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/Spacing.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/Spacing.java index 53bea8824d7607..e386db4db66420 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/Spacing.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/Spacing.java @@ -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 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; } /** diff --git a/ReactAndroid/src/test/java/com/facebook/react/fabric/FabricUIManagerTest.java b/ReactAndroid/src/test/java/com/facebook/react/fabric/FabricUIManagerTest.java index 40c8b2e78d55e7..441003004bd119 100644 --- a/ReactAndroid/src/test/java/com/facebook/react/fabric/FabricUIManagerTest.java +++ b/ReactAndroid/src/test/java/com/facebook/react/fabric/FabricUIManagerTest.java @@ -29,6 +29,7 @@ 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 void testCloneNode() { 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();