fix: handle setting transform attribute on clipPath, fixes #1152

This commit is contained in:
Mikael Sand
2019-10-19 21:59:09 +03:00
parent 5984e0629e
commit 73b21d1560
5 changed files with 14 additions and 2 deletions
@@ -333,6 +333,7 @@ abstract public class VirtualView extends ReactViewGroup {
if (mClipNode != null) {
Path clipPath = mClipNode.mClipRule == CLIP_RULE_EVENODD ? mClipNode.getPath(canvas, paint) :
mClipNode.getPath(canvas, paint, Region.Op.UNION);
clipPath.transform(mClipNode.mMatrix);
switch (mClipNode.mClipRule) {
case CLIP_RULE_EVENODD:
clipPath.setFillType(Path.FillType.EVEN_ODD);
+3 -1
View File
@@ -314,7 +314,9 @@ CGFloat const RNSVG_DEFAULT_FONT_SIZE = 12;
if (_cachedClipPath) {
CGPathRelease(_cachedClipPath);
}
_cachedClipPath = CGPathRetain([_clipNode getPath:context]);
CGAffineTransform transform = _clipNode.matrix;
_cachedClipPath = CGPathCreateCopyByTransformingPath([_clipNode getPath:context], &transform);
CGPathRetain(_cachedClipPath);
if (_clipMask) {
CGImageRelease(_clipMask);
}
+2
View File
@@ -1,12 +1,14 @@
import React from 'react';
import { requireNativeComponent } from 'react-native';
import extractClipPath from '../lib/extract/extractClipPath';
import { TransformProps } from '../lib/extract/types';
import Shape from './Shape';
export default class ClipPath extends Shape<{
id?: string;
clipPath?: string;
clipRule?: 'evenodd' | 'nonzero';
transform?: number[] | string | TransformProps;
}> {
static displayName = 'ClipPath';
+7 -1
View File
@@ -1,5 +1,6 @@
import { idPattern } from '../util';
import { ClipProps } from './types';
import extractTransform from './extractTransform';
const clipRules: { evenodd: number; nonzero: number } = {
evenodd: 0,
@@ -7,10 +8,11 @@ const clipRules: { evenodd: number; nonzero: number } = {
};
export default function extractClipPath(props: ClipProps) {
const { clipPath, clipRule } = props;
const { clipPath, clipRule, transform } = props;
const extracted: {
clipPath?: string;
clipRule?: number;
matrix?: number[];
} = {};
if (clipRule) {
@@ -31,5 +33,9 @@ export default function extractClipPath(props: ClipProps) {
}
}
if (transform) {
extracted.matrix = extractTransform(transform);
}
return extracted;
}
+1
View File
@@ -92,4 +92,5 @@ export type StrokeProps = {
export type ClipProps = {
clipPath?: string;
clipRule?: 'evenodd' | 'nonzero';
transform?: number[] | string | TransformProps;
};