Skip to content

Commit 3aa126e

Browse files
committed
fix: improve handling of transform attribute on clipPath, fixes #1152
1 parent 73b21d1 commit 3aa126e

File tree

5 files changed

+10
-20
lines changed

5 files changed

+10
-20
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
@@ -334,6 +334,7 @@ public void setResponsible(boolean responsible) {
334334
Path clipPath = mClipNode.mClipRule == CLIP_RULE_EVENODD ? mClipNode.getPath(canvas, paint) :
335335
mClipNode.getPath(canvas, paint, Region.Op.UNION);
336336
clipPath.transform(mClipNode.mMatrix);
337+
clipPath.transform(mClipNode.mTransform);
337338
switch (mClipNode.mClipRule) {
338339
case CLIP_RULE_EVENODD:
339340
clipPath.setFillType(Path.FillType.EVEN_ODD);

ios/RNSVGNode.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ - (CGPathRef)getClipPath:(CGContextRef)context
314314
if (_cachedClipPath) {
315315
CGPathRelease(_cachedClipPath);
316316
}
317-
CGAffineTransform transform = _clipNode.matrix;
317+
CGAffineTransform transform = CGAffineTransformConcat(_clipNode.matrix, _clipNode.transforms);
318318
_cachedClipPath = CGPathCreateCopyByTransformingPath([_clipNode getPath:context], &transform);
319319
CGPathRetain(_cachedClipPath);
320320
if (_clipMask) {

src/elements/ClipPath.tsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
import React from 'react';
22
import { requireNativeComponent } from 'react-native';
3-
import extractClipPath from '../lib/extract/extractClipPath';
4-
import { TransformProps } from '../lib/extract/types';
3+
import extractProps, { propsAndStyles } from '../lib/extract/extractProps';
54
import Shape from './Shape';
65

7-
export default class ClipPath extends Shape<{
8-
id?: string;
9-
clipPath?: string;
10-
clipRule?: 'evenodd' | 'nonzero';
11-
transform?: number[] | string | TransformProps;
12-
}> {
6+
export default class ClipPath extends Shape<{}> {
137
static displayName = 'ClipPath';
148

159
render() {
1610
const { props } = this;
17-
const { id, children } = props;
1811
return (
19-
<RNSVGClipPath ref={this.refMethod} name={id} {...extractClipPath(props)}>
20-
{children}
12+
<RNSVGClipPath
13+
ref={this.refMethod}
14+
{...extractProps(propsAndStyles(props), this)}
15+
>
16+
{props.children}
2117
</RNSVGClipPath>
2218
);
2319
}

src/lib/extract/extractClipPath.ts

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

54
const clipRules: { evenodd: number; nonzero: number } = {
65
evenodd: 0,
76
nonzero: 1,
87
};
98

109
export default function extractClipPath(props: ClipProps) {
11-
const { clipPath, clipRule, transform } = props;
10+
const { clipPath, clipRule } = props;
1211
const extracted: {
1312
clipPath?: string;
1413
clipRule?: number;
15-
matrix?: number[];
1614
} = {};
1715

1816
if (clipRule) {
@@ -33,9 +31,5 @@ export default function extractClipPath(props: ClipProps) {
3331
}
3432
}
3533

36-
if (transform) {
37-
extracted.matrix = extractTransform(transform);
38-
}
39-
4034
return extracted;
4135
}

src/lib/extract/types.ts

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

0 commit comments

Comments
 (0)