mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-08 01:00:43 +00:00
Simplify id/url regex matching. Allow mask/clipPath without url prefix.
Remove redundant variables. Unify use of newlines.
This commit is contained in:
@@ -20,7 +20,6 @@ export default class extends Shape {
|
||||
render() {
|
||||
const { props } = this;
|
||||
const { cx, cy, rx, ry } = props;
|
||||
|
||||
return (
|
||||
<RNSVGEllipse
|
||||
ref={ele => {
|
||||
|
||||
@@ -18,7 +18,6 @@ export default class extends Shape {
|
||||
|
||||
render() {
|
||||
const { props } = this;
|
||||
|
||||
return (
|
||||
<RNSVGGroup
|
||||
{...extractProps(props, this)}
|
||||
|
||||
+2
-5
@@ -25,9 +25,6 @@ export default class extends Shape {
|
||||
const { props } = this;
|
||||
const { preserveAspectRatio, x, y, width, height, href } = props;
|
||||
const modes = preserveAspectRatio.trim().split(spacesRegExp);
|
||||
const meetOrSlice = meetOrSliceTypes[modes[1]] || 0;
|
||||
const align = alignEnum[modes[0]] || "xMidYMid";
|
||||
|
||||
return (
|
||||
<RNSVGImage
|
||||
ref={ele => {
|
||||
@@ -38,8 +35,8 @@ export default class extends Shape {
|
||||
y={y}
|
||||
width={width}
|
||||
height={height}
|
||||
meetOrSlice={meetOrSlice}
|
||||
align={align}
|
||||
meetOrSlice={meetOrSliceTypes[modes[1]] || 0}
|
||||
align={alignEnum[modes[0]] || "xMidYMid"}
|
||||
src={Image.resolveAssetSource(href)}
|
||||
/>
|
||||
);
|
||||
|
||||
+1
-5
@@ -24,9 +24,6 @@ export default class extends Component {
|
||||
maskContentUnits,
|
||||
children,
|
||||
} = props;
|
||||
|
||||
const extractedTransform = extractTransform(maskTransform || transform || props);
|
||||
|
||||
return (
|
||||
<RNSVGMask
|
||||
ref={ele => {
|
||||
@@ -37,8 +34,7 @@ export default class extends Component {
|
||||
y={y}
|
||||
width={width}
|
||||
height={height}
|
||||
matrix={extractedTransform}
|
||||
maskTransform={extractedTransform}
|
||||
maskTransform={extractTransform(maskTransform || transform || props)}
|
||||
maskUnits={maskUnits !== undefined ? units[maskUnits] : 0}
|
||||
maskContentUnits={
|
||||
maskContentUnits !== undefined ? units[maskContentUnits] : 1
|
||||
|
||||
@@ -12,7 +12,6 @@ export default class extends Shape {
|
||||
|
||||
render() {
|
||||
const { props } = this;
|
||||
|
||||
return (
|
||||
<RNSVGPath
|
||||
ref={ele => {
|
||||
|
||||
+1
-5
@@ -27,9 +27,6 @@ export default class extends Component {
|
||||
viewBox,
|
||||
preserveAspectRatio,
|
||||
} = props;
|
||||
|
||||
const extractedTransform = extractTransform(patternTransform || transform || props);
|
||||
|
||||
return (
|
||||
<RNSVGPattern
|
||||
ref={ele => {
|
||||
@@ -40,8 +37,7 @@ export default class extends Component {
|
||||
y={y}
|
||||
width={width}
|
||||
height={height}
|
||||
matrix={extractedTransform}
|
||||
patternTransform={extractedTransform}
|
||||
patternTransform={extractTransform(patternTransform || transform || props)}
|
||||
patternUnits={units[patternUnits] || 0}
|
||||
patternContentUnits={
|
||||
patternContentUnits ? units[patternContentUnits] : 1
|
||||
|
||||
@@ -8,7 +8,6 @@ export default class extends Component {
|
||||
render() {
|
||||
const { props } = this;
|
||||
const { id, children } = props;
|
||||
|
||||
return (
|
||||
<RNSVGSymbol name={id} {...extractViewBox(props)}>
|
||||
{children}
|
||||
|
||||
@@ -24,7 +24,6 @@ export default class extends Shape {
|
||||
|
||||
render() {
|
||||
const props = this.props;
|
||||
|
||||
return (
|
||||
<RNSVGText
|
||||
ref={ele => {
|
||||
|
||||
@@ -2,11 +2,10 @@ import React from "react";
|
||||
import { requireNativeComponent } from "react-native";
|
||||
import extractText from "../lib/extract/extractText";
|
||||
import extractProps from "../lib/extract/extractProps";
|
||||
import { idPattern } from "../lib/util";
|
||||
import Shape from "./Shape";
|
||||
import TSpan from "./TSpan";
|
||||
|
||||
const idExpReg = /^#(.+)$/;
|
||||
|
||||
export default class extends Shape {
|
||||
static displayName = "TextPath";
|
||||
|
||||
@@ -22,9 +21,9 @@ export default class extends Shape {
|
||||
midLine,
|
||||
...props
|
||||
} = this.props;
|
||||
const matched = href && href.match(idExpReg);
|
||||
const matched = href && href.match(idPattern);
|
||||
const match = matched && matched[1];
|
||||
if (href && match) {
|
||||
if (match) {
|
||||
return (
|
||||
<RNSVGTextPath
|
||||
{...{
|
||||
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
import React from "react";
|
||||
import { requireNativeComponent } from "react-native";
|
||||
import {requireNativeComponent} from "react-native";
|
||||
import extractProps from "../lib/extract/extractProps";
|
||||
import { idPattern } from "../lib/util";
|
||||
import Shape from "./Shape";
|
||||
|
||||
const idExpReg = /^#(.+)$/;
|
||||
export default class extends Shape {
|
||||
static displayName = "Use";
|
||||
|
||||
@@ -21,7 +21,7 @@ export default class extends Shape {
|
||||
const { children, width, height, href } = props;
|
||||
|
||||
// match "url(#pattern)"
|
||||
const matched = href.match(idExpReg);
|
||||
const matched = href.match(idPattern);
|
||||
const match = matched && matched[1];
|
||||
|
||||
if (!match) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import Color from "color";
|
||||
import patternReg from "./patternReg";
|
||||
|
||||
const urlIdPattern = /^url\(#(.+?)\)$/;
|
||||
|
||||
export default function(colorOrBrush) {
|
||||
if (colorOrBrush === "none" || !colorOrBrush) {
|
||||
@@ -10,7 +11,7 @@ export default function(colorOrBrush) {
|
||||
return [2];
|
||||
}
|
||||
try {
|
||||
const matched = colorOrBrush.match(patternReg);
|
||||
const matched = colorOrBrush.match(urlIdPattern);
|
||||
// brush
|
||||
if (matched) {
|
||||
return [1, matched[1]];
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import clipReg from "./patternReg";
|
||||
import { idPattern } from "../util";
|
||||
|
||||
const clipRules = {
|
||||
evenodd: 0,
|
||||
@@ -14,7 +14,7 @@ export default function(props) {
|
||||
}
|
||||
|
||||
if (clipPath) {
|
||||
const matched = clipPath.match(clipReg);
|
||||
const matched = clipPath.match(idPattern);
|
||||
|
||||
if (matched) {
|
||||
clipPathProps.clipPath = matched[1];
|
||||
|
||||
@@ -50,12 +50,10 @@ export default function(props) {
|
||||
gradient.push(stop[0]);
|
||||
}
|
||||
|
||||
const gt = extractTransform(gradientTransform || transform || props);
|
||||
|
||||
return {
|
||||
gradient,
|
||||
name: id,
|
||||
gradientTransform: gt,
|
||||
gradientUnits: units[gradientUnits] || 0,
|
||||
gradientTransform: extractTransform(gradientTransform || transform || props),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import extractTransform, { props2transform } from "./extractTransform";
|
||||
import extractClipPath from "./extractClipPath";
|
||||
import extractResponder from "./extractResponder";
|
||||
import extractOpacity from "./extractOpacity";
|
||||
import urlRegex from "./patternReg";
|
||||
import { idPattern } from "../util";
|
||||
|
||||
export default function(prop, ref) {
|
||||
const props = { ...prop.style, ...prop };
|
||||
@@ -31,7 +31,7 @@ export default function(prop, ref) {
|
||||
}
|
||||
|
||||
if (mask) {
|
||||
const matched = mask.match(urlRegex);
|
||||
const matched = mask.match(idPattern);
|
||||
|
||||
if (matched) {
|
||||
extractedProps.mask = matched[1];
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
export default /^url\(#(.+?)\)$/;
|
||||
@@ -8,3 +8,5 @@ export function pickNotNil(object) {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export const idPattern = /^#(.+)$/;
|
||||
|
||||
Reference in New Issue
Block a user