mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-04 07:25:53 +00:00
Optimize input matrix handling. Improve get(Parent)TextRoot naming.
Fix doc / comment.
This commit is contained in:
@@ -55,8 +55,11 @@ class ImageShadowNode extends RenderableShadowNode {
|
||||
private int mMeetOrSlice;
|
||||
private final AtomicBoolean mLoading = new AtomicBoolean(false);
|
||||
|
||||
private static final float[] sMatrixData = new float[9];
|
||||
private static final float[] sRawMatrix = new float[9];
|
||||
private static final float[] sRawMatrix = new float[]{
|
||||
1, 0, 0,
|
||||
0, 1, 0,
|
||||
0, 0, 1
|
||||
};
|
||||
private Matrix mMatrix = new Matrix();
|
||||
|
||||
@ReactProp(name = "x")
|
||||
@@ -118,17 +121,8 @@ class ImageShadowNode extends RenderableShadowNode {
|
||||
@ReactProp(name = "matrix")
|
||||
public void setMatrix(@Nullable ReadableArray matrixArray) {
|
||||
if (matrixArray != null) {
|
||||
int matrixSize = PropHelper.toMatrixData(matrixArray, sMatrixData);
|
||||
int matrixSize = PropHelper.toMatrixData(matrixArray, sRawMatrix, mScale);
|
||||
if (matrixSize == 6) {
|
||||
sRawMatrix[0] = sMatrixData[0];
|
||||
sRawMatrix[1] = sMatrixData[2];
|
||||
sRawMatrix[2] = sMatrixData[4] * mScale;
|
||||
sRawMatrix[3] = sMatrixData[1];
|
||||
sRawMatrix[4] = sMatrixData[3];
|
||||
sRawMatrix[5] = sMatrixData[5] * mScale;
|
||||
sRawMatrix[6] = 0;
|
||||
sRawMatrix[7] = 0;
|
||||
sRawMatrix[8] = 1;
|
||||
mMatrix.setValues(sRawMatrix);
|
||||
} else if (matrixSize != -1) {
|
||||
FLog.w(ReactConstants.TAG, "RNSVG: Transform matrices must be of size 6");
|
||||
|
||||
@@ -32,8 +32,11 @@ class LinearGradientShadowNode extends DefinitionShadowNode {
|
||||
private ReadableArray mGradient;
|
||||
private Brush.BrushUnits mGradientUnits;
|
||||
|
||||
private static final float[] sMatrixData = new float[9];
|
||||
private static final float[] sRawMatrix = new float[9];
|
||||
private static final float[] sRawMatrix = new float[]{
|
||||
1, 0, 0,
|
||||
0, 1, 0,
|
||||
0, 0, 1
|
||||
};
|
||||
private Matrix mMatrix = new Matrix();
|
||||
|
||||
@ReactProp(name = "x1")
|
||||
@@ -82,17 +85,8 @@ class LinearGradientShadowNode extends DefinitionShadowNode {
|
||||
@ReactProp(name = "gradientTransform")
|
||||
public void setGradientTransform(@Nullable ReadableArray matrixArray) {
|
||||
if (matrixArray != null) {
|
||||
int matrixSize = PropHelper.toMatrixData(matrixArray, sMatrixData);
|
||||
int matrixSize = PropHelper.toMatrixData(matrixArray, sRawMatrix, mScale);
|
||||
if (matrixSize == 6) {
|
||||
sRawMatrix[0] = sMatrixData[0];
|
||||
sRawMatrix[1] = sMatrixData[2];
|
||||
sRawMatrix[2] = sMatrixData[4] * mScale;
|
||||
sRawMatrix[3] = sMatrixData[1];
|
||||
sRawMatrix[4] = sMatrixData[3];
|
||||
sRawMatrix[5] = sMatrixData[5] * mScale;
|
||||
sRawMatrix[6] = 0;
|
||||
sRawMatrix[7] = 0;
|
||||
sRawMatrix[8] = 1;
|
||||
mMatrix.setValues(sRawMatrix);
|
||||
} else if (matrixSize != -1) {
|
||||
FLog.w(ReactConstants.TAG, "RNSVG: Transform matrices must be of size 6");
|
||||
|
||||
@@ -48,27 +48,35 @@ class PropHelper {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static final int transformInputMatrixSize = 6;
|
||||
private static final int inputMatrixDataSize = 6;
|
||||
|
||||
/**
|
||||
* Converts given {@link ReadableArray} to an array of {@code float}. Writes result to the array
|
||||
* passed in {@param into}. This method will write to the output array up to the number of items
|
||||
* from the input array. If the input array is longer than output the remaining part of the input
|
||||
* will not be converted.
|
||||
* Converts given {@link ReadableArray} to a matrix data array, {@code float[6]}.
|
||||
* Writes result to the array passed in {@param into}.
|
||||
* This method will write exactly six items to the output array from the input array.
|
||||
*
|
||||
* If the input array has a different size, then only the size is returned;
|
||||
* Does not check output array size. Ensure space for at least six elements.
|
||||
*
|
||||
* @param value input array
|
||||
* @param into output array
|
||||
* @return number of items copied from input to the output array
|
||||
* @param sRawMatrix output matrix
|
||||
* @param mScale current resolution scaling
|
||||
* @return size of input array
|
||||
*/
|
||||
static int toMatrixData(ReadableArray value, float[] into) {
|
||||
static int toMatrixData(ReadableArray value, float[] sRawMatrix, float mScale) {
|
||||
int fromSize = value.size();
|
||||
if (fromSize != transformInputMatrixSize) {
|
||||
if (fromSize != inputMatrixDataSize) {
|
||||
return fromSize;
|
||||
}
|
||||
for (int i = 0; i < transformInputMatrixSize; i++) {
|
||||
into[i] = (float) value.getDouble(i);
|
||||
}
|
||||
return transformInputMatrixSize;
|
||||
|
||||
sRawMatrix[0] = (float) value.getDouble(0);
|
||||
sRawMatrix[1] = (float) value.getDouble(2);
|
||||
sRawMatrix[2] = (float) value.getDouble(4) * mScale;
|
||||
sRawMatrix[3] = (float) value.getDouble(1);
|
||||
sRawMatrix[4] = (float) value.getDouble(3);
|
||||
sRawMatrix[5] = (float) value.getDouble(5) * mScale;
|
||||
|
||||
return inputMatrixDataSize;
|
||||
}
|
||||
|
||||
static private final Pattern percentageRegExp = Pattern.compile("^(-?\\d+(?:\\.\\d+)?)%$");
|
||||
|
||||
@@ -33,8 +33,11 @@ class RadialGradientShadowNode extends DefinitionShadowNode {
|
||||
private ReadableArray mGradient;
|
||||
private Brush.BrushUnits mGradientUnits;
|
||||
|
||||
private static final float[] sMatrixData = new float[9];
|
||||
private static final float[] sRawMatrix = new float[9];
|
||||
private static final float[] sRawMatrix = new float[]{
|
||||
1, 0, 0,
|
||||
0, 1, 0,
|
||||
0, 0, 1
|
||||
};
|
||||
private Matrix mMatrix = new Matrix();
|
||||
|
||||
@ReactProp(name = "fx")
|
||||
@@ -95,17 +98,8 @@ class RadialGradientShadowNode extends DefinitionShadowNode {
|
||||
@ReactProp(name = "gradientTransform")
|
||||
public void setGradientTransform(@Nullable ReadableArray matrixArray) {
|
||||
if (matrixArray != null) {
|
||||
int matrixSize = PropHelper.toMatrixData(matrixArray, sMatrixData);
|
||||
int matrixSize = PropHelper.toMatrixData(matrixArray, sRawMatrix, mScale);
|
||||
if (matrixSize == 6) {
|
||||
sRawMatrix[0] = sMatrixData[0];
|
||||
sRawMatrix[1] = sMatrixData[2];
|
||||
sRawMatrix[2] = sMatrixData[4] * mScale;
|
||||
sRawMatrix[3] = sMatrixData[1];
|
||||
sRawMatrix[4] = sMatrixData[3];
|
||||
sRawMatrix[5] = sMatrixData[5] * mScale;
|
||||
sRawMatrix[6] = 0;
|
||||
sRawMatrix[7] = 0;
|
||||
sRawMatrix[8] = 1;
|
||||
mMatrix.setValues(sRawMatrix);
|
||||
} else if (matrixSize != -1) {
|
||||
FLog.w(ReactConstants.TAG, "RNSVG: Transform matrices must be of size 6");
|
||||
|
||||
@@ -38,8 +38,11 @@ abstract class VirtualNode extends LayoutShadowNode {
|
||||
|
||||
static final float MIN_OPACITY_FOR_DRAW = 0.01f;
|
||||
|
||||
private static final float[] sMatrixData = new float[9];
|
||||
private static final float[] sRawMatrix = new float[9];
|
||||
private static final float[] sRawMatrix = new float[]{
|
||||
1, 0, 0,
|
||||
0, 1, 0,
|
||||
0, 0, 1
|
||||
};
|
||||
float mOpacity = 1f;
|
||||
private double mFontSize = -1;
|
||||
private double mParentFontSize = -1;
|
||||
@@ -72,23 +75,23 @@ abstract class VirtualNode extends LayoutShadowNode {
|
||||
}
|
||||
|
||||
GroupShadowNode getTextRoot() {
|
||||
GroupShadowNode shadowNode = getShadowNode(GroupShadowNode.class);
|
||||
GroupShadowNode shadowNode = getTextRoot(GroupShadowNode.class);
|
||||
if (shadowNode == null) {
|
||||
return getShadowNode(TextShadowNode.class);
|
||||
return getTextRoot(TextShadowNode.class);
|
||||
}
|
||||
return shadowNode;
|
||||
}
|
||||
|
||||
private GroupShadowNode getParentTextRoot() {
|
||||
GroupShadowNode shadowNode = getParentShadowNode(GroupShadowNode.class);
|
||||
GroupShadowNode shadowNode = getParentTextRoot(GroupShadowNode.class);
|
||||
if (shadowNode == null) {
|
||||
return getParentShadowNode(TextShadowNode.class);
|
||||
return getParentTextRoot(TextShadowNode.class);
|
||||
}
|
||||
return shadowNode;
|
||||
}
|
||||
|
||||
@android.support.annotation.Nullable
|
||||
private GroupShadowNode getParentShadowNode(Class shadowNodeClass) {
|
||||
private GroupShadowNode getParentTextRoot(Class shadowNodeClass) {
|
||||
ReactShadowNode node = this.getParent();
|
||||
if (mParentTextRoot == null) {
|
||||
while (node != null) {
|
||||
@@ -111,7 +114,7 @@ abstract class VirtualNode extends LayoutShadowNode {
|
||||
}
|
||||
|
||||
@android.support.annotation.Nullable
|
||||
private GroupShadowNode getShadowNode(Class shadowNodeClass) {
|
||||
private GroupShadowNode getTextRoot(Class shadowNodeClass) {
|
||||
VirtualNode node = this;
|
||||
if (mTextRoot == null) {
|
||||
while (node != null) {
|
||||
@@ -214,17 +217,8 @@ abstract class VirtualNode extends LayoutShadowNode {
|
||||
@ReactProp(name = "matrix")
|
||||
public void setMatrix(@Nullable ReadableArray matrixArray) {
|
||||
if (matrixArray != null) {
|
||||
int matrixSize = PropHelper.toMatrixData(matrixArray, sMatrixData);
|
||||
int matrixSize = PropHelper.toMatrixData(matrixArray, sRawMatrix, mScale);
|
||||
if (matrixSize == 6) {
|
||||
sRawMatrix[0] = sMatrixData[0];
|
||||
sRawMatrix[1] = sMatrixData[2];
|
||||
sRawMatrix[2] = sMatrixData[4] * mScale;
|
||||
sRawMatrix[3] = sMatrixData[1];
|
||||
sRawMatrix[4] = sMatrixData[3];
|
||||
sRawMatrix[5] = sMatrixData[5] * mScale;
|
||||
sRawMatrix[6] = 0;
|
||||
sRawMatrix[7] = 0;
|
||||
sRawMatrix[8] = 1;
|
||||
mMatrix.setValues(sRawMatrix);
|
||||
} else if (matrixSize != -1) {
|
||||
FLog.w(ReactConstants.TAG, "RNSVG: Transform matrices must be of size 6");
|
||||
|
||||
Reference in New Issue
Block a user