Files
react-native-svg/elements/Polygon.js
T
Mikael Sand 1e25870f5d Simplify and optimize property handling logic
Remove redundant toString calls / type transforms.
The view managers handle the different types natively.
2018-10-12 18:52:23 +03:00

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`}
/>
);
}
}