Skip to content

Commit f2130ad

Browse files
authored
fix: handle null passed to matrix and tintColor (software-mansion#1904)
PR adding handling of null values passed to matrix and tintColor props on Android. It should not happen from normal render method, but can still be passed with Animated or Reanimated through native updates or setNativeProps.
1 parent 8cf4068 commit f2130ad

File tree

2 files changed

+18
-21
lines changed

2 files changed

+18
-21
lines changed

android/src/main/java/com/horcrux/svg/SvgView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ private void clearChildCache() {
186186
}
187187

188188
public void setTintColor(Integer tintColor) {
189-
mTintColor = tintColor;
189+
mTintColor = tintColor != null ? tintColor : 0;
190190
invalidate();
191191
clearChildCache();
192192
}

android/src/main/java/com/horcrux/svg/VirtualView.java

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -291,30 +291,27 @@ public void setOpacity(float opacity) {
291291
}
292292

293293
public void setMatrix(Dynamic matrixArray) {
294-
ReadableType type = matrixArray.getType();
295-
if (!matrixArray.isNull() && type.equals(ReadableType.Array)) {
296-
ReadableArray matrix = matrixArray.asArray();
297-
setMatrix(matrix);
294+
boolean isArrayType = !matrixArray.isNull() && matrixArray.getType().equals(ReadableType.Array);
295+
setMatrix(isArrayType ? matrixArray.asArray() : null);
296+
}
297+
298+
public void setMatrix(@Nullable ReadableArray matrixArray) {
299+
if (matrixArray != null) {
300+
int matrixSize = PropHelper.toMatrixData(matrixArray, sRawMatrix, mScale);
301+
if (matrixSize == 6) {
302+
if (mMatrix == null) {
303+
mMatrix = new Matrix();
304+
mInvMatrix = new Matrix();
305+
}
306+
mMatrix.setValues(sRawMatrix);
307+
mInvertible = mMatrix.invert(mInvMatrix);
308+
} else if (matrixSize != -1) {
309+
FLog.w(ReactConstants.TAG, "RNSVG: Transform matrices must be of size 6");
310+
}
298311
} else {
299312
mMatrix.reset();
300313
mInvMatrix.reset();
301314
mInvertible = true;
302-
super.invalidate();
303-
clearParentCache();
304-
}
305-
}
306-
307-
public void setMatrix(ReadableArray matrixArray) {
308-
int matrixSize = PropHelper.toMatrixData(matrixArray, sRawMatrix, mScale);
309-
if (matrixSize == 6) {
310-
if (mMatrix == null) {
311-
mMatrix = new Matrix();
312-
mInvMatrix = new Matrix();
313-
}
314-
mMatrix.setValues(sRawMatrix);
315-
mInvertible = mMatrix.invert(mInvMatrix);
316-
} else if (matrixSize != -1) {
317-
FLog.w(ReactConstants.TAG, "RNSVG: Transform matrices must be of size 6");
318315
}
319316
super.invalidate();
320317
clearParentCache();

0 commit comments

Comments
 (0)