mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-07 08:45:00 +00:00
Fix #844
Handle svg root width/height attribute strings containing px on iOS Inherit fill/stroke attributes from Mask elements Set default bounding box of mask to fill viewport / allow missing x, y, width, height on mask element
This commit is contained in:
@@ -88,9 +88,12 @@ class GroupView extends RenderableView {
|
|||||||
final GroupView self = this;
|
final GroupView self = this;
|
||||||
final RectF groupRect = new RectF();
|
final RectF groupRect = new RectF();
|
||||||
for (int i = 0; i < getChildCount(); i++) {
|
for (int i = 0; i < getChildCount(); i++) {
|
||||||
View lNode = getChildAt(i);
|
View child = getChildAt(i);
|
||||||
if (lNode instanceof VirtualView) {
|
if (child instanceof MaskView) {
|
||||||
VirtualView node = ((VirtualView)lNode);
|
continue;
|
||||||
|
}
|
||||||
|
if (child instanceof VirtualView) {
|
||||||
|
VirtualView node = ((VirtualView)child);
|
||||||
if (node instanceof RenderableView) {
|
if (node instanceof RenderableView) {
|
||||||
((RenderableView)node).mergeProperties(self);
|
((RenderableView)node).mergeProperties(self);
|
||||||
}
|
}
|
||||||
@@ -111,8 +114,8 @@ class GroupView extends RenderableView {
|
|||||||
if (node.isResponsible()) {
|
if (node.isResponsible()) {
|
||||||
svg.enableTouchEvents();
|
svg.enableTouchEvents();
|
||||||
}
|
}
|
||||||
} else if (lNode instanceof SvgView) {
|
} else if (child instanceof SvgView) {
|
||||||
SvgView svgView = (SvgView)lNode;
|
SvgView svgView = (SvgView)child;
|
||||||
svgView.drawChildren(canvas);
|
svgView.drawChildren(canvas);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -133,6 +136,9 @@ class GroupView extends RenderableView {
|
|||||||
|
|
||||||
for (int i = 0; i < getChildCount(); i++) {
|
for (int i = 0; i < getChildCount(); i++) {
|
||||||
View node = getChildAt(i);
|
View node = getChildAt(i);
|
||||||
|
if (node instanceof MaskView) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (node instanceof VirtualView) {
|
if (node instanceof VirtualView) {
|
||||||
VirtualView n = (VirtualView)node;
|
VirtualView n = (VirtualView)node;
|
||||||
Matrix transform = n.mMatrix;
|
Matrix transform = n.mMatrix;
|
||||||
@@ -150,6 +156,9 @@ class GroupView extends RenderableView {
|
|||||||
final Path.Op pop = Path.Op.valueOf(op.name());
|
final Path.Op pop = Path.Op.valueOf(op.name());
|
||||||
for (int i = 0; i < getChildCount(); i++) {
|
for (int i = 0; i < getChildCount(); i++) {
|
||||||
View node = getChildAt(i);
|
View node = getChildAt(i);
|
||||||
|
if (node instanceof MaskView) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (node instanceof VirtualView) {
|
if (node instanceof VirtualView) {
|
||||||
VirtualView n = (VirtualView)node;
|
VirtualView n = (VirtualView)node;
|
||||||
Matrix transform = n.mMatrix;
|
Matrix transform = n.mMatrix;
|
||||||
@@ -169,6 +178,9 @@ class GroupView extends RenderableView {
|
|||||||
final Region r = new Region();
|
final Region r = new Region();
|
||||||
for (int i = 0; i < getChildCount(); i++) {
|
for (int i = 0; i < getChildCount(); i++) {
|
||||||
View node = getChildAt(i);
|
View node = getChildAt(i);
|
||||||
|
if (node instanceof MaskView) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (node instanceof VirtualView) {
|
if (node instanceof VirtualView) {
|
||||||
VirtualView n = (VirtualView)node;
|
VirtualView n = (VirtualView)node;
|
||||||
Matrix transform = n.mMatrix;
|
Matrix transform = n.mMatrix;
|
||||||
@@ -221,6 +233,9 @@ class GroupView extends RenderableView {
|
|||||||
if (!(child instanceof VirtualView)) {
|
if (!(child instanceof VirtualView)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (child instanceof MaskView) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
VirtualView node = (VirtualView) child;
|
VirtualView node = (VirtualView) child;
|
||||||
|
|
||||||
|
|||||||
+9
-1
@@ -1,12 +1,20 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { requireNativeComponent } from "react-native";
|
import { requireNativeComponent } from "react-native";
|
||||||
import extractTransform from "../lib/extract/extractTransform";
|
import extractTransform from "../lib/extract/extractTransform";
|
||||||
|
import extractProps from "react-native-svg/lib/extract/extractProps";
|
||||||
import units from "../lib/units";
|
import units from "../lib/units";
|
||||||
import Shape from "./Shape";
|
import Shape from "./Shape";
|
||||||
|
|
||||||
export default class Mask extends Shape {
|
export default class Mask extends Shape {
|
||||||
static displayName = "Mask";
|
static displayName = "Mask";
|
||||||
|
|
||||||
|
static defaultProps = {
|
||||||
|
x: "0%",
|
||||||
|
y: "0%",
|
||||||
|
width: "100%",
|
||||||
|
height: "100%",
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { props } = this;
|
const { props } = this;
|
||||||
const {
|
const {
|
||||||
@@ -24,7 +32,7 @@ export default class Mask extends Shape {
|
|||||||
return (
|
return (
|
||||||
<RNSVGMask
|
<RNSVGMask
|
||||||
ref={this.refMethod}
|
ref={this.refMethod}
|
||||||
name={id}
|
{...extractProps({ ...props, x: null, y: null }, this)}
|
||||||
x={x}
|
x={x}
|
||||||
y={y}
|
y={y}
|
||||||
width={width}
|
width={width}
|
||||||
|
|||||||
+4
-2
@@ -89,9 +89,11 @@ export default class Svg extends Shape {
|
|||||||
strokeMiterlimit,
|
strokeMiterlimit,
|
||||||
} = stylesAndProps;
|
} = stylesAndProps;
|
||||||
|
|
||||||
|
const w = parseInt(width);
|
||||||
|
const h = parseInt(height);
|
||||||
const dimensions = width && height ? {
|
const dimensions = width && height ? {
|
||||||
width: width[width.length - 1] === "%" ? width : +width,
|
width: isNaN(w) || width[width.length - 1] === '%' ? width : w,
|
||||||
height: height[height.length - 1] === "%" ? height : +height,
|
height: isNaN(h) || height[height.length - 1] === '%' ? height : h,
|
||||||
flex: 0,
|
flex: 0,
|
||||||
} : null;
|
} : null;
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -34,7 +34,7 @@ export default class Use extends Shape {
|
|||||||
<RNSVGUse
|
<RNSVGUse
|
||||||
ref={this.refMethod}
|
ref={this.refMethod}
|
||||||
{...extractProps(
|
{...extractProps(
|
||||||
{ ...props, x: undefined, y: undefined },
|
{ ...props, x: null, y: null },
|
||||||
this,
|
this,
|
||||||
)}
|
)}
|
||||||
href={match}
|
href={match}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#import "RNSVGGroup.h"
|
#import "RNSVGGroup.h"
|
||||||
#import "RNSVGClipPath.h"
|
#import "RNSVGClipPath.h"
|
||||||
|
#import "RNSVGMask.h"
|
||||||
|
|
||||||
@implementation RNSVGGroup
|
@implementation RNSVGGroup
|
||||||
{
|
{
|
||||||
@@ -38,7 +39,9 @@
|
|||||||
__block CGRect bounds = CGRectNull;
|
__block CGRect bounds = CGRectNull;
|
||||||
|
|
||||||
[self traverseSubviews:^(UIView *node) {
|
[self traverseSubviews:^(UIView *node) {
|
||||||
if ([node isKindOfClass:[RNSVGNode class]]) {
|
if ([node isKindOfClass:[RNSVGMask class]]) {
|
||||||
|
// no-op
|
||||||
|
} else if ([node isKindOfClass:[RNSVGNode class]]) {
|
||||||
RNSVGNode* svgNode = (RNSVGNode*)node;
|
RNSVGNode* svgNode = (RNSVGNode*)node;
|
||||||
if (svgNode.responsible && !self.svgView.responsible) {
|
if (svgNode.responsible && !self.svgView.responsible) {
|
||||||
self.svgView.responsible = YES;
|
self.svgView.responsible = YES;
|
||||||
@@ -203,7 +206,7 @@
|
|||||||
[self.svgView defineTemplate:weakSelf templateName:self.name];
|
[self.svgView defineTemplate:weakSelf templateName:self.name];
|
||||||
}
|
}
|
||||||
|
|
||||||
[self traverseSubviews:^(__kindof RNSVGNode *node) {
|
[self traverseSubviews:^(RNSVGNode *node) {
|
||||||
if ([node isKindOfClass:[RNSVGNode class]]) {
|
if ([node isKindOfClass:[RNSVGNode class]]) {
|
||||||
[node parseReference];
|
[node parseReference];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user