Implement Cloning for ART Views

Reviewed By: achen1

Differential Revision: D7058410

fbshipit-source-id: 394330654be1ab70853f78580c2543e04a3efb7c
This commit is contained in:
David Vacca 2018-02-23 17:28:32 -08:00 committed by Facebook Github Bot
parent 486ac9dc82
commit 1b63da753f
6 changed files with 69 additions and 6 deletions

View File

@ -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);
}
}

View File

@ -123,6 +123,7 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
}
}
@Override
public ReactShadowNodeImpl mutableCopy() {
return new ReactShadowNodeImpl(this);
}

View File

@ -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 class ARTGroupShadowNode extends ARTVirtualNode {
}
}
@Override
public ReactShadowNodeImpl mutableCopy() {
return new ARTGroupShadowNode(this);
}
@Override
public boolean isVirtual() {
return true;

View File

@ -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);

View File

@ -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;

View File

@ -37,6 +37,13 @@ public abstract class ARTVirtualNode extends ReactShadowNodeImpl {
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;