mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-05 16:04:38 +00:00
fix: improve handling of transform attribute on clipPath, fixes #1152
This commit is contained in:
@@ -334,6 +334,7 @@ abstract public class VirtualView extends ReactViewGroup {
|
|||||||
Path clipPath = mClipNode.mClipRule == CLIP_RULE_EVENODD ? mClipNode.getPath(canvas, paint) :
|
Path clipPath = mClipNode.mClipRule == CLIP_RULE_EVENODD ? mClipNode.getPath(canvas, paint) :
|
||||||
mClipNode.getPath(canvas, paint, Region.Op.UNION);
|
mClipNode.getPath(canvas, paint, Region.Op.UNION);
|
||||||
clipPath.transform(mClipNode.mMatrix);
|
clipPath.transform(mClipNode.mMatrix);
|
||||||
|
clipPath.transform(mClipNode.mTransform);
|
||||||
switch (mClipNode.mClipRule) {
|
switch (mClipNode.mClipRule) {
|
||||||
case CLIP_RULE_EVENODD:
|
case CLIP_RULE_EVENODD:
|
||||||
clipPath.setFillType(Path.FillType.EVEN_ODD);
|
clipPath.setFillType(Path.FillType.EVEN_ODD);
|
||||||
|
|||||||
+1
-1
@@ -314,7 +314,7 @@ CGFloat const RNSVG_DEFAULT_FONT_SIZE = 12;
|
|||||||
if (_cachedClipPath) {
|
if (_cachedClipPath) {
|
||||||
CGPathRelease(_cachedClipPath);
|
CGPathRelease(_cachedClipPath);
|
||||||
}
|
}
|
||||||
CGAffineTransform transform = _clipNode.matrix;
|
CGAffineTransform transform = CGAffineTransformConcat(_clipNode.matrix, _clipNode.transforms);
|
||||||
_cachedClipPath = CGPathCreateCopyByTransformingPath([_clipNode getPath:context], &transform);
|
_cachedClipPath = CGPathCreateCopyByTransformingPath([_clipNode getPath:context], &transform);
|
||||||
CGPathRetain(_cachedClipPath);
|
CGPathRetain(_cachedClipPath);
|
||||||
if (_clipMask) {
|
if (_clipMask) {
|
||||||
|
|||||||
@@ -1,23 +1,19 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { requireNativeComponent } from 'react-native';
|
import { requireNativeComponent } from 'react-native';
|
||||||
import extractClipPath from '../lib/extract/extractClipPath';
|
import extractProps, { propsAndStyles } from '../lib/extract/extractProps';
|
||||||
import { TransformProps } from '../lib/extract/types';
|
|
||||||
import Shape from './Shape';
|
import Shape from './Shape';
|
||||||
|
|
||||||
export default class ClipPath extends Shape<{
|
export default class ClipPath extends Shape<{}> {
|
||||||
id?: string;
|
|
||||||
clipPath?: string;
|
|
||||||
clipRule?: 'evenodd' | 'nonzero';
|
|
||||||
transform?: number[] | string | TransformProps;
|
|
||||||
}> {
|
|
||||||
static displayName = 'ClipPath';
|
static displayName = 'ClipPath';
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { props } = this;
|
const { props } = this;
|
||||||
const { id, children } = props;
|
|
||||||
return (
|
return (
|
||||||
<RNSVGClipPath ref={this.refMethod} name={id} {...extractClipPath(props)}>
|
<RNSVGClipPath
|
||||||
{children}
|
ref={this.refMethod}
|
||||||
|
{...extractProps(propsAndStyles(props), this)}
|
||||||
|
>
|
||||||
|
{props.children}
|
||||||
</RNSVGClipPath>
|
</RNSVGClipPath>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { idPattern } from '../util';
|
import { idPattern } from '../util';
|
||||||
import { ClipProps } from './types';
|
import { ClipProps } from './types';
|
||||||
import extractTransform from './extractTransform';
|
|
||||||
|
|
||||||
const clipRules: { evenodd: number; nonzero: number } = {
|
const clipRules: { evenodd: number; nonzero: number } = {
|
||||||
evenodd: 0,
|
evenodd: 0,
|
||||||
@@ -8,11 +7,10 @@ const clipRules: { evenodd: number; nonzero: number } = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default function extractClipPath(props: ClipProps) {
|
export default function extractClipPath(props: ClipProps) {
|
||||||
const { clipPath, clipRule, transform } = props;
|
const { clipPath, clipRule } = props;
|
||||||
const extracted: {
|
const extracted: {
|
||||||
clipPath?: string;
|
clipPath?: string;
|
||||||
clipRule?: number;
|
clipRule?: number;
|
||||||
matrix?: number[];
|
|
||||||
} = {};
|
} = {};
|
||||||
|
|
||||||
if (clipRule) {
|
if (clipRule) {
|
||||||
@@ -33,9 +31,5 @@ export default function extractClipPath(props: ClipProps) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (transform) {
|
|
||||||
extracted.matrix = extractTransform(transform);
|
|
||||||
}
|
|
||||||
|
|
||||||
return extracted;
|
return extracted;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,5 +92,4 @@ export type StrokeProps = {
|
|||||||
export type ClipProps = {
|
export type ClipProps = {
|
||||||
clipPath?: string;
|
clipPath?: string;
|
||||||
clipRule?: 'evenodd' | 'nonzero';
|
clipRule?: 'evenodd' | 'nonzero';
|
||||||
transform?: number[] | string | TransformProps;
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user