mirror of
https://github.com/zoriya/react-native-svg.git
synced 2025-12-20 05:55:10 +00:00
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. Will commit PR for `<Polygon>` as well.
48 lines
1.2 KiB
JavaScript
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 = "Polyline";
|
|
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)}`}
|
|
/>
|
|
);
|
|
}
|
|
}
|