Skip to content

Commit 73b21d1

Browse files
committed
fix: handle setting transform attribute on clipPath, fixes #1152
1 parent 5984e06 commit 73b21d1

File tree

5 files changed

+14
-2
lines changed

5 files changed

+14
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ public void setResponsible(boolean responsible) {
333333
if (mClipNode != null) {
334334
Path clipPath = mClipNode.mClipRule == CLIP_RULE_EVENODD ? mClipNode.getPath(canvas, paint) :
335335
mClipNode.getPath(canvas, paint, Region.Op.UNION);
336+
clipPath.transform(mClipNode.mMatrix);
336337
switch (mClipNode.mClipRule) {
337338
case CLIP_RULE_EVENODD:
338339
clipPath.setFillType(Path.FillType.EVEN_ODD);

ios/RNSVGNode.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,9 @@ - (CGPathRef)getClipPath:(CGContextRef)context
314314
if (_cachedClipPath) {
315315
CGPathRelease(_cachedClipPath);
316316
}
317-
_cachedClipPath = CGPathRetain([_clipNode getPath:context]);
317+
CGAffineTransform transform = _clipNode.matrix;
318+
_cachedClipPath = CGPathCreateCopyByTransformingPath([_clipNode getPath:context], &transform);
319+
CGPathRetain(_cachedClipPath);
318320
if (_clipMask) {
319321
CGImageRelease(_clipMask);
320322
}

src/elements/ClipPath.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import React from 'react';
22
import { requireNativeComponent } from 'react-native';
33
import extractClipPath from '../lib/extract/extractClipPath';
4+
import { TransformProps } from '../lib/extract/types';
45
import Shape from './Shape';
56

67
export default class ClipPath extends Shape<{
78
id?: string;
89
clipPath?: string;
910
clipRule?: 'evenodd' | 'nonzero';
11+
transform?: number[] | string | TransformProps;
1012
}> {
1113
static displayName = 'ClipPath';
1214

src/lib/extract/extractClipPath.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import { idPattern } from '../util';
22
import { ClipProps } from './types';
3+
import extractTransform from './extractTransform';
34

45
const clipRules: { evenodd: number; nonzero: number } = {
56
evenodd: 0,
67
nonzero: 1,
78
};
89

910
export default function extractClipPath(props: ClipProps) {
10-
const { clipPath, clipRule } = props;
11+
const { clipPath, clipRule, transform } = props;
1112
const extracted: {
1213
clipPath?: string;
1314
clipRule?: number;
15+
matrix?: number[];
1416
} = {};
1517

1618
if (clipRule) {
@@ -31,5 +33,9 @@ export default function extractClipPath(props: ClipProps) {
3133
}
3234
}
3335

36+
if (transform) {
37+
extracted.matrix = extractTransform(transform);
38+
}
39+
3440
return extracted;
3541
}

src/lib/extract/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,5 @@ export type StrokeProps = {
9292
export type ClipProps = {
9393
clipPath?: string;
9494
clipRule?: 'evenodd' | 'nonzero';
95+
transform?: number[] | string | TransformProps;
9596
};

0 commit comments

Comments
 (0)