mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-09 01:25:01 +00:00
1e25870f5d
Remove redundant toString calls / type transforms. The view managers handle the different types natively.
50 lines
1.2 KiB
JavaScript
50 lines
1.2 KiB
JavaScript
import React from "react";
|
|
import PropTypes from "prop-types";
|
|
import Path from "./Path";
|
|
import { pathProps } from "../lib/props";
|
|
import extractPolyPoints from "../lib/extract/extractPolyPoints";
|
|
import Shape from "./Shape";
|
|
|
|
export default class extends Shape {
|
|
static displayName = "Polygon";
|
|
static propTypes = {
|
|
...pathProps,
|
|
points: PropTypes.oneOfType([PropTypes.string, PropTypes.array])
|
|
.isRequired,
|
|
};
|
|
|
|
static defaultProps = {
|
|
points: "",
|
|
};
|
|
|
|
setNativeProps = props => {
|
|
let { points } = props;
|
|
if (points) {
|
|
if (Array.isArray(points)) {
|
|
points = points.join(",");
|
|
}
|
|
props.d = `M${extractPolyPoints(points)}`;
|
|
}
|
|
this.root.setNativeProps(props);
|
|
};
|
|
|
|
render() {
|
|
const { props } = this;
|
|
let { points } = props;
|
|
|
|
if (Array.isArray(points)) {
|
|
points = points.join(",");
|
|
}
|
|
|
|
return (
|
|
<Path
|
|
ref={ele => {
|
|
this.root = ele;
|
|
}}
|
|
{...props}
|
|
d={`M${extractPolyPoints(points)}z`}
|
|
/>
|
|
);
|
|
}
|
|
}
|