Files
react-native-svg/elements/Polygon.js
ShaMan123 3a1b139d15 update setNativeProps()
When updating `points` prop, `setNativeProps` must send a valid `d` prop to `this.root` which is a `<Path>'.
It needs more work, couldn't get it working perfectly. I'm new to RN.
Commit PR for `<Polyline>` as well.
2018-06-03 13:55:01 +03:00

48 lines
1.2 KiB
JavaScript

import React, { Component } from "react";
import PropTypes from "prop-types";
import Path from "./Path";
import { pathProps } from "../lib/props";
import extractPolyPoints from "../lib/extract/extractPolyPoints";
export default class extends Component {
static displayName = "Polygon";
static propTypes = {
...pathProps,
points: PropTypes.oneOfType([PropTypes.string, PropTypes.array])
.isRequired
};
static defaultProps = {
points: ""
};
setNativeProps = (...args) => {
//noinspection JSUnresolvedFunction
var points = [...args][0].points;
if (points) {
if (Array.isArray(points)) {
points = points.join(",");
}
[...args][0].d = `M${extractPolyPoints(points)}`
}
this.root.setNativeProps(...args);
};
render() {
let points = this.props.points;
if (Array.isArray(points)) {
points = points.join(",");
}
return (
<Path
ref={ele => {
this.root = ele;
}}
{...this.props}
d={`M${extractPolyPoints(points)}z`}
/>
);
}
}