diff --git a/ReactAndroid/src/main/java/com/facebook/react/common/ArrayUtils.java b/ReactAndroid/src/main/java/com/facebook/react/common/ArrayUtils.java new file mode 100644 index 00000000000000..0036e9bac13abb --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/react/common/ArrayUtils.java @@ -0,0 +1,11 @@ +package com.facebook.react.common; + +import java.util.Arrays; + +public class ArrayUtils { + + public static float[] copyArray(float[] array) { + return array == null ? null : Arrays.copyOf(array, array.length); + } + +} 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 c12f5fb9ff8a4d..59ab9b69ec3787 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNodeImpl.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNodeImpl.java @@ -123,6 +123,7 @@ public ReactShadowNodeImpl(ReactShadowNodeImpl original) { } } + @Override public ReactShadowNodeImpl mutableCopy() { return new ReactShadowNodeImpl(this); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/art/ARTGroupShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/views/art/ARTGroupShadowNode.java index 780147294f1a44..35cf8169ca18fe 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/art/ARTGroupShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/art/ARTGroupShadowNode.java @@ -7,6 +7,7 @@ package com.facebook.react.views.art; +import com.facebook.react.uimanager.ReactShadowNodeImpl; import javax.annotation.Nullable; import android.graphics.Canvas; @@ -25,6 +26,13 @@ public class ARTGroupShadowNode extends ARTVirtualNode { protected @Nullable RectF mClipping; + public ARTGroupShadowNode() { } + + public ARTGroupShadowNode(ARTGroupShadowNode node) { + super(node); + this.mClipping = new RectF(node.mClipping); + } + @ReactProp(name = "clipping") public void setClipping(@Nullable ReadableArray clippingDims) { float[] clippingData = PropHelper.toFloatArray(clippingDims); @@ -34,6 +42,11 @@ public void setClipping(@Nullable ReadableArray clippingDims) { } } + @Override + public ReactShadowNodeImpl mutableCopy() { + return new ARTGroupShadowNode(this); + } + @Override public boolean isVirtual() { return true; diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/art/ARTShapeShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/views/art/ARTShapeShadowNode.java index dc8980ae2ebc06..e60ad880397b89 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/art/ARTShapeShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/art/ARTShapeShadowNode.java @@ -7,22 +7,22 @@ package com.facebook.react.views.art; -import javax.annotation.Nullable; - import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.DashPathEffect; +import android.graphics.LinearGradient; import android.graphics.Paint; import android.graphics.Path; import android.graphics.RectF; -import android.graphics.DashPathEffect; -import android.graphics.LinearGradient; import android.graphics.Shader; -import android.graphics.Color; - import com.facebook.common.logging.FLog; import com.facebook.react.bridge.JSApplicationIllegalArgumentException; import com.facebook.react.bridge.ReadableArray; import com.facebook.react.common.ReactConstants; import com.facebook.react.uimanager.annotations.ReactProp; +import javax.annotation.Nullable; + +import static com.facebook.react.common.ArrayUtils.copyArray; /** * Shadow node for virtual ARTShape view @@ -58,6 +58,24 @@ public class ARTShapeShadowNode extends ARTVirtualNode { private int mStrokeCap = CAP_ROUND; private int mStrokeJoin = JOIN_ROUND; + public ARTShapeShadowNode() { } + + public ARTShapeShadowNode(ARTShapeShadowNode node) { + super(node); + mPath = new Path(node.mPath); + mStrokeColor = copyArray(node.mStrokeColor); + mBrushData = copyArray(node.mBrushData); + mStrokeDash = copyArray(node.mStrokeDash); + mStrokeWidth = node.mStrokeWidth; + mStrokeCap = node.mStrokeCap; + mStrokeJoin = node.mStrokeJoin; + } + + @Override + public ARTShapeShadowNode mutableCopy() { + return new ARTShapeShadowNode(this); + } + @ReactProp(name = "d") public void setShapePath(@Nullable ReadableArray shapePath) { float[] pathData = PropHelper.toFloatArray(shapePath); diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/art/ARTTextShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/views/art/ARTTextShadowNode.java index b10f59bff8d247..4a52e7a28a06c1 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/art/ARTTextShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/art/ARTTextShadowNode.java @@ -40,6 +40,19 @@ public class ARTTextShadowNode extends ARTShapeShadowNode { private @Nullable ReadableMap mFrame; private int mTextAlignment = TEXT_ALIGNMENT_LEFT; + public ARTTextShadowNode() { } + + public ARTTextShadowNode(ARTTextShadowNode node) { + super(node); + mTextAlignment = node.mTextAlignment; + mFrame = node.mFrame; // copy reference as mFrame is already immutable + } + + @Override + public ARTShapeShadowNode mutableCopy() { + return new ARTTextShadowNode(this); + } + @ReactProp(name = "frame") public void setFrame(@Nullable ReadableMap frame) { mFrame = frame; diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/art/ARTVirtualNode.java b/ReactAndroid/src/main/java/com/facebook/react/views/art/ARTVirtualNode.java index 5cc9d49f65f984..158afd16eac943 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/art/ARTVirtualNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/art/ARTVirtualNode.java @@ -37,6 +37,13 @@ public ARTVirtualNode() { mScale = DisplayMetricsHolder.getWindowDisplayMetrics().density; } + protected ARTVirtualNode(ARTVirtualNode artVirtualNode) { + super(artVirtualNode); + mScale = artVirtualNode.mScale; + mOpacity = artVirtualNode.mOpacity; + mMatrix = new Matrix(artVirtualNode.mMatrix); + } + @Override public boolean isVirtual() { return true;