Skip to content
This repository has been archived by the owner on Mar 21, 2022. It is now read-only.

Commit

Permalink
fix: improve handling of transform attribute on clipPath, fixes softw…
Browse files Browse the repository at this point in the history
  • Loading branch information
msand committed Oct 19, 2019
1 parent 73b21d1 commit 3aa126e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 20 deletions.
1 change: 1 addition & 0 deletions android/src/main/java/com/horcrux/svg/VirtualView.java
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ public void setResponsible(boolean responsible) {
Path clipPath = mClipNode.mClipRule == CLIP_RULE_EVENODD ? mClipNode.getPath(canvas, paint) :
mClipNode.getPath(canvas, paint, Region.Op.UNION);
clipPath.transform(mClipNode.mMatrix);
clipPath.transform(mClipNode.mTransform);
switch (mClipNode.mClipRule) {
case CLIP_RULE_EVENODD:
clipPath.setFillType(Path.FillType.EVEN_ODD);
Expand Down
2 changes: 1 addition & 1 deletion ios/RNSVGNode.m
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ - (CGPathRef)getClipPath:(CGContextRef)context
if (_cachedClipPath) {
CGPathRelease(_cachedClipPath);
}
CGAffineTransform transform = _clipNode.matrix;
CGAffineTransform transform = CGAffineTransformConcat(_clipNode.matrix, _clipNode.transforms);
_cachedClipPath = CGPathCreateCopyByTransformingPath([_clipNode getPath:context], &transform);
CGPathRetain(_cachedClipPath);
if (_clipMask) {
Expand Down
18 changes: 7 additions & 11 deletions src/elements/ClipPath.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import React from 'react';
import { requireNativeComponent } from 'react-native';
import extractClipPath from '../lib/extract/extractClipPath';
import { TransformProps } from '../lib/extract/types';
import extractProps, { propsAndStyles } from '../lib/extract/extractProps';
import Shape from './Shape';

export default class ClipPath extends Shape<{
id?: string;
clipPath?: string;
clipRule?: 'evenodd' | 'nonzero';
transform?: number[] | string | TransformProps;
}> {
export default class ClipPath extends Shape<{}> {
static displayName = 'ClipPath';

render() {
const { props } = this;
const { id, children } = props;
return (
<RNSVGClipPath ref={this.refMethod} name={id} {...extractClipPath(props)}>
{children}
<RNSVGClipPath
ref={this.refMethod}
{...extractProps(propsAndStyles(props), this)}
>
{props.children}
</RNSVGClipPath>
);
}
Expand Down
8 changes: 1 addition & 7 deletions src/lib/extract/extractClipPath.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { idPattern } from '../util';
import { ClipProps } from './types';
import extractTransform from './extractTransform';

const clipRules: { evenodd: number; nonzero: number } = {
evenodd: 0,
nonzero: 1,
};

export default function extractClipPath(props: ClipProps) {
const { clipPath, clipRule, transform } = props;
const { clipPath, clipRule } = props;
const extracted: {
clipPath?: string;
clipRule?: number;
matrix?: number[];
} = {};

if (clipRule) {
Expand All @@ -33,9 +31,5 @@ export default function extractClipPath(props: ClipProps) {
}
}

if (transform) {
extracted.matrix = extractTransform(transform);
}

return extracted;
}
1 change: 0 additions & 1 deletion src/lib/extract/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,4 @@ export type StrokeProps = {
export type ClipProps = {
clipPath?: string;
clipRule?: 'evenodd' | 'nonzero';
transform?: number[] | string | TransformProps;
};

0 comments on commit 3aa126e

Please sign in to comment.