mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-05 07:59:28 +00:00
Fix linting, make Polygon and Polyline extend Shape
This commit is contained in:
+4
-4
@@ -1,7 +1,7 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import { Image, requireNativeComponent } from "react-native";
|
import { Image, requireNativeComponent } from "react-native";
|
||||||
import ImageSourcePropType from 'react-native/Libraries/Image/ImageSourcePropType';
|
import ImageSourcePropType from "react-native/Libraries/Image/ImageSourcePropType";
|
||||||
import { ImageAttributes } from "../lib/attributes";
|
import { ImageAttributes } from "../lib/attributes";
|
||||||
import { numberProp, touchableProps, responderProps } from "../lib/props";
|
import { numberProp, touchableProps, responderProps } from "../lib/props";
|
||||||
import Shape from "./Shape";
|
import Shape from "./Shape";
|
||||||
@@ -20,7 +20,7 @@ export default class extends Shape {
|
|||||||
width: numberProp.isRequired,
|
width: numberProp.isRequired,
|
||||||
height: numberProp.isRequired,
|
height: numberProp.isRequired,
|
||||||
href: ImageSourcePropType,
|
href: ImageSourcePropType,
|
||||||
preserveAspectRatio: PropTypes.string
|
preserveAspectRatio: PropTypes.string,
|
||||||
};
|
};
|
||||||
|
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
@@ -28,7 +28,7 @@ export default class extends Shape {
|
|||||||
y: 0,
|
y: 0,
|
||||||
width: 0,
|
width: 0,
|
||||||
height: 0,
|
height: 0,
|
||||||
preserveAspectRatio: "xMidYMid meet"
|
preserveAspectRatio: "xMidYMid meet",
|
||||||
};
|
};
|
||||||
|
|
||||||
setNativeProps = (...args) => {
|
setNativeProps = (...args) => {
|
||||||
@@ -60,5 +60,5 @@ export default class extends Shape {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const RNSVGImage = requireNativeComponent("RNSVGImage", null, {
|
const RNSVGImage = requireNativeComponent("RNSVGImage", null, {
|
||||||
nativeOnly: ImageAttributes
|
nativeOnly: ImageAttributes,
|
||||||
});
|
});
|
||||||
|
|||||||
+18
-14
@@ -1,13 +1,13 @@
|
|||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from "prop-types";
|
||||||
import { requireNativeComponent } from "react-native";
|
import { requireNativeComponent } from "react-native";
|
||||||
import { numberProp } from '../lib/props';
|
import { numberProp } from "../lib/props";
|
||||||
import PATTERN_UNITS from '../lib/PATTERN_UNITS';
|
import PATTERN_UNITS from "../lib/PATTERN_UNITS";
|
||||||
import { MaskAttributes } from '../lib/attributes';
|
import { MaskAttributes } from "../lib/attributes";
|
||||||
import extractTransform from '../lib/extract/extractTransform';
|
import extractTransform from "../lib/extract/extractTransform";
|
||||||
|
|
||||||
export default class extends Component {
|
export default class extends Component {
|
||||||
static displayName = 'Mask';
|
static displayName = "Mask";
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
id: PropTypes.string.isRequired,
|
id: PropTypes.string.isRequired,
|
||||||
x: numberProp,
|
x: numberProp,
|
||||||
@@ -15,10 +15,10 @@ export default class extends Component {
|
|||||||
width: numberProp,
|
width: numberProp,
|
||||||
height: numberProp,
|
height: numberProp,
|
||||||
maskTransform: PropTypes.string,
|
maskTransform: PropTypes.string,
|
||||||
maskUnits: PropTypes.oneOf(['userSpaceOnUse', 'objectBoundingBox']),
|
maskUnits: PropTypes.oneOf(["userSpaceOnUse", "objectBoundingBox"]),
|
||||||
maskContentUnits: PropTypes.oneOf([
|
maskContentUnits: PropTypes.oneOf([
|
||||||
'userSpaceOnUse',
|
"userSpaceOnUse",
|
||||||
'objectBoundingBox',
|
"objectBoundingBox",
|
||||||
]),
|
]),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -35,8 +35,6 @@ export default class extends Component {
|
|||||||
maskUnits,
|
maskUnits,
|
||||||
maskContentUnits,
|
maskContentUnits,
|
||||||
children,
|
children,
|
||||||
viewBox,
|
|
||||||
preserveAspectRatio,
|
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
let extractedTransform;
|
let extractedTransform;
|
||||||
@@ -57,8 +55,14 @@ export default class extends Component {
|
|||||||
maskheight={`${height}`}
|
maskheight={`${height}`}
|
||||||
matrix={extractedTransform}
|
matrix={extractedTransform}
|
||||||
maskTransform={extractedTransform}
|
maskTransform={extractedTransform}
|
||||||
maskUnits={maskUnits !== undefined ? PATTERN_UNITS[maskUnits] : 0}
|
maskUnits={
|
||||||
maskContentUnits={maskContentUnits !== undefined ? PATTERN_UNITS[maskContentUnits] : 1}
|
maskUnits !== undefined ? PATTERN_UNITS[maskUnits] : 0
|
||||||
|
}
|
||||||
|
maskContentUnits={
|
||||||
|
maskContentUnits !== undefined
|
||||||
|
? PATTERN_UNITS[maskContentUnits]
|
||||||
|
: 1
|
||||||
|
}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</RNSVGMask>
|
</RNSVGMask>
|
||||||
@@ -66,6 +70,6 @@ export default class extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const RNSVGMask = requireNativeComponent('RNSVGMask', null, {
|
const RNSVGMask = requireNativeComponent("RNSVGMask", null, {
|
||||||
nativeOnly: MaskAttributes,
|
nativeOnly: MaskAttributes,
|
||||||
});
|
});
|
||||||
|
|||||||
+14
-12
@@ -1,14 +1,14 @@
|
|||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from "prop-types";
|
||||||
import { requireNativeComponent } from "react-native";
|
import { requireNativeComponent } from "react-native";
|
||||||
import { numberProp } from '../lib/props';
|
import { numberProp } from "../lib/props";
|
||||||
import PATTERN_UNITS from '../lib/PATTERN_UNITS';
|
import PATTERN_UNITS from "../lib/PATTERN_UNITS";
|
||||||
import { PatternAttributes } from '../lib/attributes';
|
import { PatternAttributes } from "../lib/attributes";
|
||||||
import extractTransform from '../lib/extract/extractTransform';
|
import extractTransform from "../lib/extract/extractTransform";
|
||||||
import extractViewBox from "react-native-svg/lib/extract/extractViewBox";
|
import extractViewBox from "react-native-svg/lib/extract/extractViewBox";
|
||||||
|
|
||||||
export default class extends Component {
|
export default class extends Component {
|
||||||
static displayName = 'Pattern';
|
static displayName = "Pattern";
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
id: PropTypes.string.isRequired,
|
id: PropTypes.string.isRequired,
|
||||||
x: numberProp,
|
x: numberProp,
|
||||||
@@ -16,13 +16,13 @@ export default class extends Component {
|
|||||||
width: numberProp,
|
width: numberProp,
|
||||||
height: numberProp,
|
height: numberProp,
|
||||||
patternTransform: PropTypes.string,
|
patternTransform: PropTypes.string,
|
||||||
patternUnits: PropTypes.oneOf(['userSpaceOnUse', 'objectBoundingBox']),
|
patternUnits: PropTypes.oneOf(["userSpaceOnUse", "objectBoundingBox"]),
|
||||||
patternContentUnits: PropTypes.oneOf([
|
patternContentUnits: PropTypes.oneOf([
|
||||||
'userSpaceOnUse',
|
"userSpaceOnUse",
|
||||||
'objectBoundingBox',
|
"objectBoundingBox",
|
||||||
]),
|
]),
|
||||||
viewBox: PropTypes.string,
|
viewBox: PropTypes.string,
|
||||||
preserveAspectRatio: PropTypes.string
|
preserveAspectRatio: PropTypes.string,
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@@ -61,7 +61,9 @@ export default class extends Component {
|
|||||||
matrix={extractedTransform}
|
matrix={extractedTransform}
|
||||||
patternTransform={extractedTransform}
|
patternTransform={extractedTransform}
|
||||||
patternUnits={PATTERN_UNITS[patternUnits] || 0}
|
patternUnits={PATTERN_UNITS[patternUnits] || 0}
|
||||||
patternContentUnits={patternContentUnits ? PATTERN_UNITS[patternContentUnits] : 1}
|
patternContentUnits={
|
||||||
|
patternContentUnits ? PATTERN_UNITS[patternContentUnits] : 1
|
||||||
|
}
|
||||||
{...extractViewBox({ viewBox, preserveAspectRatio })}
|
{...extractViewBox({ viewBox, preserveAspectRatio })}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
@@ -70,6 +72,6 @@ export default class extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const RNSVGPattern = requireNativeComponent('RNSVGPattern', null, {
|
const RNSVGPattern = requireNativeComponent("RNSVGPattern", null, {
|
||||||
nativeOnly: PatternAttributes,
|
nativeOnly: PatternAttributes,
|
||||||
});
|
});
|
||||||
|
|||||||
+5
-4
@@ -1,10 +1,11 @@
|
|||||||
import React, { Component } from "react";
|
import React from "react";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import Path from "./Path";
|
import Path from "./Path";
|
||||||
import { pathProps } from "../lib/props";
|
import { pathProps } from "../lib/props";
|
||||||
import extractPolyPoints from "../lib/extract/extractPolyPoints";
|
import extractPolyPoints from "../lib/extract/extractPolyPoints";
|
||||||
|
import Shape from "./Shape";
|
||||||
|
|
||||||
export default class extends Component {
|
export default class extends Shape {
|
||||||
static displayName = "Polygon";
|
static displayName = "Polygon";
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
...pathProps,
|
...pathProps,
|
||||||
@@ -18,12 +19,12 @@ export default class extends Component {
|
|||||||
|
|
||||||
setNativeProps = (...args) => {
|
setNativeProps = (...args) => {
|
||||||
//noinspection JSUnresolvedFunction
|
//noinspection JSUnresolvedFunction
|
||||||
var points = [...args][0].points;
|
let points = [...args][0].points;
|
||||||
if (points) {
|
if (points) {
|
||||||
if (Array.isArray(points)) {
|
if (Array.isArray(points)) {
|
||||||
points = points.join(",");
|
points = points.join(",");
|
||||||
}
|
}
|
||||||
[...args][0].d = `M${extractPolyPoints(points)}`
|
[...args][0].d = `M${extractPolyPoints(points)}`;
|
||||||
}
|
}
|
||||||
this.root.setNativeProps(...args);
|
this.root.setNativeProps(...args);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import React, { Component } from "react";
|
import React from "react";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import Path from "./Path";
|
import Path from "./Path";
|
||||||
import { pathProps } from "../lib/props";
|
import { pathProps } from "../lib/props";
|
||||||
import extractPolyPoints from "../lib/extract/extractPolyPoints";
|
import extractPolyPoints from "../lib/extract/extractPolyPoints";
|
||||||
|
import Shape from "./Shape";
|
||||||
|
|
||||||
export default class extends Component {
|
export default class extends Shape {
|
||||||
static displayName = "Polyline";
|
static displayName = "Polyline";
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
...pathProps,
|
...pathProps,
|
||||||
@@ -18,12 +19,12 @@ export default class extends Component {
|
|||||||
|
|
||||||
setNativeProps = (...args) => {
|
setNativeProps = (...args) => {
|
||||||
//noinspection JSUnresolvedFunction
|
//noinspection JSUnresolvedFunction
|
||||||
var points = [...args][0].points;
|
let points = [...args][0].points;
|
||||||
if (points) {
|
if (points) {
|
||||||
if (Array.isArray(points)) {
|
if (Array.isArray(points)) {
|
||||||
points = points.join(",");
|
points = points.join(",");
|
||||||
}
|
}
|
||||||
[...args][0].d = `M${extractPolyPoints(points)}`
|
[...args][0].d = `M${extractPolyPoints(points)}`;
|
||||||
}
|
}
|
||||||
this.root.setNativeProps(...args);
|
this.root.setNativeProps(...args);
|
||||||
};
|
};
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
//noinspection JSUnresolvedVariable
|
//noinspection JSUnresolvedVariable
|
||||||
import React, { Component } from "react";
|
import React from "react";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import {
|
import {
|
||||||
ViewPropTypes,
|
ViewPropTypes,
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ export default function(colorOrBrush) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (colorOrBrush === 'currentColor') {
|
if (colorOrBrush === "currentColor") {
|
||||||
return [2]
|
return [2];
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
let matched = colorOrBrush.match(patternReg);
|
let matched = colorOrBrush.match(patternReg);
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import extractOpacity from "./extractOpacity";
|
|||||||
import extractTransform from "./extractTransform";
|
import extractTransform from "./extractTransform";
|
||||||
import PATTERN_UNITS from "../PATTERN_UNITS";
|
import PATTERN_UNITS from "../PATTERN_UNITS";
|
||||||
import percentToFloat from "../percentToFloat";
|
import percentToFloat from "../percentToFloat";
|
||||||
import Stop from "../../elements/Stop";
|
|
||||||
|
|
||||||
export default function(props) {
|
export default function(props) {
|
||||||
if (!props.id) {
|
if (!props.id) {
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ export function extractFont(prop) {
|
|||||||
fontVariantLigatures,
|
fontVariantLigatures,
|
||||||
fontFeatureSettings
|
fontFeatureSettings
|
||||||
},
|
},
|
||||||
prop => !_.isNil(prop)
|
p => !_.isNil(p)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (typeof font === "string") {
|
if (typeof font === "string") {
|
||||||
|
|||||||
Reference in New Issue
Block a user