Skip to content

Commit

Permalink
Implement Cloning for ART Views
Browse files Browse the repository at this point in the history
Reviewed By: achen1

Differential Revision: D7058410

fbshipit-source-id: 394330654be1ab70853f78580c2543e04a3efb7c
  • Loading branch information
mdvacca authored and facebook-github-bot committed Feb 24, 2018
1 parent 486ac9d commit 1b63da7
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public ReactShadowNodeImpl(ReactShadowNodeImpl original) {
}
}

@Override
public ReactShadowNodeImpl mutableCopy() {
return new ReactShadowNodeImpl(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

package com.facebook.react.views.art;

import com.facebook.react.uimanager.ReactShadowNodeImpl;
import javax.annotation.Nullable;

import android.graphics.Canvas;
Expand All @@ -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);
Expand All @@ -34,6 +42,11 @@ public void setClipping(@Nullable ReadableArray clippingDims) {
}
}

@Override
public ReactShadowNodeImpl mutableCopy() {
return new ARTGroupShadowNode(this);
}

@Override
public boolean isVirtual() {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1b63da7

Please sign in to comment.