mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-09 17:30:58 +00:00
Lift default setNativeProps and refMethod implementation to Shape class
This commit is contained in:
+1
-7
@@ -12,18 +12,12 @@ export default class Circle extends Shape {
|
|||||||
r: 0,
|
r: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
setNativeProps = (...args) => {
|
|
||||||
this.root.setNativeProps(...args);
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { props } = this;
|
const { props } = this;
|
||||||
const { cx, cy, r } = props;
|
const { cx, cy, r } = props;
|
||||||
return (
|
return (
|
||||||
<RNSVGCircle
|
<RNSVGCircle
|
||||||
ref={ele => {
|
ref={this.refMethod}
|
||||||
this.root = ele;
|
|
||||||
}}
|
|
||||||
{...extractProps(props, this)}
|
{...extractProps(props, this)}
|
||||||
cx={cx}
|
cx={cx}
|
||||||
cy={cy}
|
cy={cy}
|
||||||
|
|||||||
@@ -5,17 +5,11 @@ import extractClipPath from "../lib/extract/extractClipPath";
|
|||||||
export default class ClipPath extends Component {
|
export default class ClipPath extends Component {
|
||||||
static displayName = "ClipPath";
|
static displayName = "ClipPath";
|
||||||
|
|
||||||
setNativeProps = (...args) => {
|
|
||||||
this.root.setNativeProps(...args);
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { id, children } = this.props;
|
const { id, children } = this.props;
|
||||||
return (
|
return (
|
||||||
<RNSVGClipPath
|
<RNSVGClipPath
|
||||||
ref={ele => {
|
ref={this.refMethod}
|
||||||
this.root = ele;
|
|
||||||
}}
|
|
||||||
name={id}
|
name={id}
|
||||||
{...extractClipPath(this.props)}
|
{...extractClipPath(this.props)}
|
||||||
>
|
>
|
||||||
|
|||||||
+1
-7
@@ -13,18 +13,12 @@ export default class Ellipse extends Shape {
|
|||||||
ry: 0,
|
ry: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
setNativeProps = (...args) => {
|
|
||||||
this.root.setNativeProps(...args);
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { props } = this;
|
const { props } = this;
|
||||||
const { cx, cy, rx, ry } = props;
|
const { cx, cy, rx, ry } = props;
|
||||||
return (
|
return (
|
||||||
<RNSVGEllipse
|
<RNSVGEllipse
|
||||||
ref={ele => {
|
ref={this.refMethod}
|
||||||
this.root = ele;
|
|
||||||
}}
|
|
||||||
{...extractProps(props, this)}
|
{...extractProps(props, this)}
|
||||||
cx={cx}
|
cx={cx}
|
||||||
cy={cy}
|
cy={cy}
|
||||||
|
|||||||
+1
-3
@@ -20,11 +20,9 @@ export default class G extends Shape {
|
|||||||
const { props } = this;
|
const { props } = this;
|
||||||
return (
|
return (
|
||||||
<RNSVGGroup
|
<RNSVGGroup
|
||||||
|
ref={this.refMethod}
|
||||||
{...extractProps(props, this)}
|
{...extractProps(props, this)}
|
||||||
font={extractFont(props)}
|
font={extractFont(props)}
|
||||||
ref={ele => {
|
|
||||||
this.root = ele;
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
{props.children}
|
{props.children}
|
||||||
</RNSVGGroup>
|
</RNSVGGroup>
|
||||||
|
|||||||
+2
-8
@@ -6,7 +6,7 @@ import Shape from "./Shape";
|
|||||||
|
|
||||||
const spacesRegExp = /\s+/;
|
const spacesRegExp = /\s+/;
|
||||||
|
|
||||||
export default class Image extends Shape {
|
export default class SvgImage extends Shape {
|
||||||
static displayName = "Image";
|
static displayName = "Image";
|
||||||
|
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
@@ -17,19 +17,13 @@ export default class Image extends Shape {
|
|||||||
preserveAspectRatio: "xMidYMid meet",
|
preserveAspectRatio: "xMidYMid meet",
|
||||||
};
|
};
|
||||||
|
|
||||||
setNativeProps = props => {
|
|
||||||
this.root.setNativeProps(props);
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { props } = this;
|
const { props } = this;
|
||||||
const { preserveAspectRatio, x, y, width, height, href } = props;
|
const { preserveAspectRatio, x, y, width, height, href } = props;
|
||||||
const modes = preserveAspectRatio.trim().split(spacesRegExp);
|
const modes = preserveAspectRatio.trim().split(spacesRegExp);
|
||||||
return (
|
return (
|
||||||
<RNSVGImage
|
<RNSVGImage
|
||||||
ref={ele => {
|
ref={this.refMethod}
|
||||||
this.root = ele;
|
|
||||||
}}
|
|
||||||
{...extractProps({ ...props, x: null, y: null }, this)}
|
{...extractProps({ ...props, x: null, y: null }, this)}
|
||||||
x={x}
|
x={x}
|
||||||
y={y}
|
y={y}
|
||||||
|
|||||||
+1
-7
@@ -13,18 +13,12 @@ export default class Line extends Shape {
|
|||||||
y2: 0,
|
y2: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
setNativeProps = (...args) => {
|
|
||||||
this.root.setNativeProps(...args);
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { props } = this;
|
const { props } = this;
|
||||||
const { x1, y1, x2, y2 } = props;
|
const { x1, y1, x2, y2 } = props;
|
||||||
return (
|
return (
|
||||||
<RNSVGLine
|
<RNSVGLine
|
||||||
ref={ele => {
|
ref={this.refMethod}
|
||||||
this.root = ele;
|
|
||||||
}}
|
|
||||||
{...extractProps(props, this)}
|
{...extractProps(props, this)}
|
||||||
x1={x1}
|
x1={x1}
|
||||||
y1={y1}
|
y1={y1}
|
||||||
|
|||||||
@@ -12,18 +12,12 @@ export default class LinearGradient extends Component {
|
|||||||
y2: "0%",
|
y2: "0%",
|
||||||
};
|
};
|
||||||
|
|
||||||
setNativeProps = (...args) => {
|
|
||||||
this.root.setNativeProps(...args);
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { props } = this;
|
const { props } = this;
|
||||||
const { x1, y1, x2, y2 } = props;
|
const { x1, y1, x2, y2 } = props;
|
||||||
return (
|
return (
|
||||||
<RNSVGLinearGradient
|
<RNSVGLinearGradient
|
||||||
ref={ele => {
|
ref={this.refMethod}
|
||||||
this.root = ele;
|
|
||||||
}}
|
|
||||||
x1={x1}
|
x1={x1}
|
||||||
y1={y1}
|
y1={y1}
|
||||||
x2={x2}
|
x2={x2}
|
||||||
|
|||||||
+1
-7
@@ -6,10 +6,6 @@ import units from "../lib/units";
|
|||||||
export default class Mask extends Component {
|
export default class Mask extends Component {
|
||||||
static displayName = "Mask";
|
static displayName = "Mask";
|
||||||
|
|
||||||
setNativeProps = props => {
|
|
||||||
this.root.setNativeProps(props);
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { props } = this;
|
const { props } = this;
|
||||||
const {
|
const {
|
||||||
@@ -26,9 +22,7 @@ export default class Mask extends Component {
|
|||||||
} = props;
|
} = props;
|
||||||
return (
|
return (
|
||||||
<RNSVGMask
|
<RNSVGMask
|
||||||
ref={ele => {
|
ref={this.refMethod}
|
||||||
this.root = ele;
|
|
||||||
}}
|
|
||||||
name={id}
|
name={id}
|
||||||
x={x}
|
x={x}
|
||||||
y={y}
|
y={y}
|
||||||
|
|||||||
+1
-7
@@ -6,17 +6,11 @@ import Shape from "./Shape";
|
|||||||
export default class Path extends Shape {
|
export default class Path extends Shape {
|
||||||
static displayName = "Path";
|
static displayName = "Path";
|
||||||
|
|
||||||
setNativeProps = (...args) => {
|
|
||||||
this.root.setNativeProps(...args);
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { props } = this;
|
const { props } = this;
|
||||||
return (
|
return (
|
||||||
<RNSVGPath
|
<RNSVGPath
|
||||||
ref={ele => {
|
ref={this.refMethod}
|
||||||
this.root = ele;
|
|
||||||
}}
|
|
||||||
{...extractProps(props, this)}
|
{...extractProps(props, this)}
|
||||||
d={props.d}
|
d={props.d}
|
||||||
/>
|
/>
|
||||||
|
|||||||
+1
-7
@@ -7,10 +7,6 @@ import units from "../lib/units";
|
|||||||
export default class Pattern extends Component {
|
export default class Pattern extends Component {
|
||||||
static displayName = "Pattern";
|
static displayName = "Pattern";
|
||||||
|
|
||||||
setNativeProps = props => {
|
|
||||||
this.root.setNativeProps(props);
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { props } = this;
|
const { props } = this;
|
||||||
const {
|
const {
|
||||||
@@ -29,9 +25,7 @@ export default class Pattern extends Component {
|
|||||||
} = props;
|
} = props;
|
||||||
return (
|
return (
|
||||||
<RNSVGPattern
|
<RNSVGPattern
|
||||||
ref={ele => {
|
ref={this.refMethod}
|
||||||
this.root = ele;
|
|
||||||
}}
|
|
||||||
name={id}
|
name={id}
|
||||||
x={x}
|
x={x}
|
||||||
y={y}
|
y={y}
|
||||||
|
|||||||
+2
-4
@@ -23,11 +23,9 @@ export default class Polygon extends Shape {
|
|||||||
const { points } = props;
|
const { points } = props;
|
||||||
return (
|
return (
|
||||||
<Path
|
<Path
|
||||||
ref={ele => {
|
ref={this.refMethod}
|
||||||
this.root = ele;
|
|
||||||
}}
|
|
||||||
{...props}
|
|
||||||
d={`M${extractPolyPoints(points)}z`}
|
d={`M${extractPolyPoints(points)}z`}
|
||||||
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,11 +23,9 @@ export default class Polyline extends Shape {
|
|||||||
const { points } = props;
|
const { points } = props;
|
||||||
return (
|
return (
|
||||||
<Path
|
<Path
|
||||||
ref={ele => {
|
ref={this.refMethod}
|
||||||
this.root = ele;
|
|
||||||
}}
|
|
||||||
{...this.props}
|
|
||||||
d={`M${extractPolyPoints(points)}`}
|
d={`M${extractPolyPoints(points)}`}
|
||||||
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,18 +13,12 @@ export default class RadialGradient extends Component {
|
|||||||
r: "50%",
|
r: "50%",
|
||||||
};
|
};
|
||||||
|
|
||||||
setNativeProps = (...args) => {
|
|
||||||
this.root.setNativeProps(...args);
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { props } = this;
|
const { props } = this;
|
||||||
const { fx, fy, rx, ry, r, cx, cy } = props;
|
const { fx, fy, rx, ry, r, cx, cy } = props;
|
||||||
return (
|
return (
|
||||||
<RNSVGRadialGradient
|
<RNSVGRadialGradient
|
||||||
ref={ele => {
|
ref={this.refMethod}
|
||||||
this.root = ele;
|
|
||||||
}}
|
|
||||||
fx={fx}
|
fx={fx}
|
||||||
fy={fy}
|
fy={fy}
|
||||||
rx={rx || r}
|
rx={rx || r}
|
||||||
|
|||||||
+1
-7
@@ -15,18 +15,12 @@ export default class Rect extends Shape {
|
|||||||
ry: 0,
|
ry: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
setNativeProps = props => {
|
|
||||||
this.root.setNativeProps(props);
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { props } = this;
|
const { props } = this;
|
||||||
const { x, y, width, height, rx, ry } = props;
|
const { x, y, width, height, rx, ry } = props;
|
||||||
return (
|
return (
|
||||||
<RNSVGRect
|
<RNSVGRect
|
||||||
ref={ele => {
|
ref={this.refMethod}
|
||||||
this.root = ele;
|
|
||||||
}}
|
|
||||||
{...extractProps(
|
{...extractProps(
|
||||||
{
|
{
|
||||||
...props,
|
...props,
|
||||||
|
|||||||
@@ -15,4 +15,10 @@ export default class Shape extends Component {
|
|||||||
}
|
}
|
||||||
this.state = this.touchableGetInitialState();
|
this.state = this.touchableGetInitialState();
|
||||||
}
|
}
|
||||||
|
refMethod = ref => {
|
||||||
|
this.root = ref;
|
||||||
|
};
|
||||||
|
setNativeProps = props => {
|
||||||
|
this.root.setNativeProps(props);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-3
@@ -104,9 +104,7 @@ export default class Svg extends Shape {
|
|||||||
bbHeight={String(height)}
|
bbHeight={String(height)}
|
||||||
{...extractResponder(props, this)}
|
{...extractResponder(props, this)}
|
||||||
{...extractViewBox({ viewBox, preserveAspectRatio })}
|
{...extractViewBox({ viewBox, preserveAspectRatio })}
|
||||||
ref={ele => {
|
ref={this.refMethod}
|
||||||
this.root = ele;
|
|
||||||
}}
|
|
||||||
style={[
|
style={[
|
||||||
styles.svg,
|
styles.svg,
|
||||||
style,
|
style,
|
||||||
|
|||||||
+1
-3
@@ -25,9 +25,7 @@ export default class TSpan extends Shape {
|
|||||||
const props = this.props;
|
const props = this.props;
|
||||||
return (
|
return (
|
||||||
<RNSVGTSpan
|
<RNSVGTSpan
|
||||||
ref={ele => {
|
ref={this.refMethod}
|
||||||
this.root = ele;
|
|
||||||
}}
|
|
||||||
{...extractProps(
|
{...extractProps(
|
||||||
{
|
{
|
||||||
...props,
|
...props,
|
||||||
|
|||||||
+1
-3
@@ -26,9 +26,7 @@ export default class Text extends Shape {
|
|||||||
const props = this.props;
|
const props = this.props;
|
||||||
return (
|
return (
|
||||||
<RNSVGText
|
<RNSVGText
|
||||||
ref={ele => {
|
ref={this.refMethod}
|
||||||
this.root = ele;
|
|
||||||
}}
|
|
||||||
{...extractProps(
|
{...extractProps(
|
||||||
{
|
{
|
||||||
...props,
|
...props,
|
||||||
|
|||||||
+11
-15
@@ -39,18 +39,7 @@ export default class TextPath extends Shape {
|
|||||||
if (match) {
|
if (match) {
|
||||||
return (
|
return (
|
||||||
<RNSVGTextPath
|
<RNSVGTextPath
|
||||||
ref={ele => {
|
ref={this.refMethod}
|
||||||
this.root = ele;
|
|
||||||
}}
|
|
||||||
{...{
|
|
||||||
href: match,
|
|
||||||
startOffset: startOffset || 0,
|
|
||||||
method,
|
|
||||||
spacing,
|
|
||||||
side,
|
|
||||||
alignmentBaseline,
|
|
||||||
midLine,
|
|
||||||
}}
|
|
||||||
{...extractProps(
|
{...extractProps(
|
||||||
{
|
{
|
||||||
...props,
|
...props,
|
||||||
@@ -65,6 +54,15 @@ export default class TextPath extends Shape {
|
|||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
)}
|
)}
|
||||||
|
{...{
|
||||||
|
href: match,
|
||||||
|
startOffset: startOffset || 0,
|
||||||
|
method,
|
||||||
|
spacing,
|
||||||
|
side,
|
||||||
|
alignmentBaseline,
|
||||||
|
midLine,
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -76,9 +74,7 @@ export default class TextPath extends Shape {
|
|||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
<TSpan
|
<TSpan
|
||||||
ref={ele => {
|
ref={this.refMethod}
|
||||||
this.root = ele;
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</TSpan>
|
</TSpan>
|
||||||
|
|||||||
+2
-8
@@ -1,5 +1,5 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import {requireNativeComponent} from "react-native";
|
import { requireNativeComponent } from "react-native";
|
||||||
import extractProps from "../lib/extract/extractProps";
|
import extractProps from "../lib/extract/extractProps";
|
||||||
import { idPattern } from "../lib/util";
|
import { idPattern } from "../lib/util";
|
||||||
import Shape from "./Shape";
|
import Shape from "./Shape";
|
||||||
@@ -12,10 +12,6 @@ export default class Use extends Shape {
|
|||||||
height: 0,
|
height: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
setNativeProps = props => {
|
|
||||||
this.root.setNativeProps(props);
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { props } = this;
|
const { props } = this;
|
||||||
const { children, width, height, href } = props;
|
const { children, width, height, href } = props;
|
||||||
@@ -34,9 +30,7 @@ export default class Use extends Shape {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<RNSVGUse
|
<RNSVGUse
|
||||||
ref={ele => {
|
ref={this.refMethod}
|
||||||
this.root = ele;
|
|
||||||
}}
|
|
||||||
{...extractProps(props, this)}
|
{...extractProps(props, this)}
|
||||||
href={match}
|
href={match}
|
||||||
width={width}
|
width={width}
|
||||||
|
|||||||
+1
-1
@@ -9,4 +9,4 @@ export function pickNotNil(object) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const idPattern = /^#(.+)$/;
|
export const idPattern = /#([^\)]+)\)?$/;
|
||||||
|
|||||||
Reference in New Issue
Block a user