Fix strokeDasharray handling of odd number of length values and the 'none' value.

This commit is contained in:
Mikael Sand
2017-07-25 21:58:07 +03:00
parent 48cfe71aca
commit 54efe3ad1e
2 changed files with 13 additions and 8 deletions
+10 -5
View File
@@ -29,13 +29,18 @@ export default function(props, styleProperties) {
const strokeWidth = props.strokeWidth;
let strokeDasharray = props.strokeDasharray;
if (typeof strokeDasharray === 'string') {
if (!strokeDasharray || strokeDasharray === 'none') {
strokeDasharray = null;
} else if (typeof strokeDasharray === 'string') {
strokeDasharray = strokeDasharray.split(separator).map(dash => +dash);
}
// strokeDasharray length must be more than 1.
if (strokeDasharray && strokeDasharray.length === 1) {
strokeDasharray.push(strokeDasharray[0]);
// <dasharray> It's a list of comma and/or white space separated <length>s
// and <percentage>s that specify the lengths of alternating dashes and gaps.
// If an odd number of values is provided, then the list of values is repeated
// to yield an even number of values. Thus, 5,3,2 is equivalent to 5,3,2,5,3,2.
if (strokeDasharray && (strokeDasharray.length % 2) === 1) {
strokeDasharray.concat(strokeDasharray);
}
return {
@@ -43,7 +48,7 @@ export default function(props, styleProperties) {
strokeOpacity: extractOpacity(props.strokeOpacity),
strokeLinecap: caps[props.strokeLinecap] || 0,
strokeLinejoin: joins[props.strokeLinejoin] || 0,
strokeDasharray: strokeDasharray || null,
strokeDasharray: strokeDasharray,
strokeWidth: strokeWidth || '1',
strokeDashoffset: strokeDasharray ? (+props.strokeDashoffset || 0) : null,
strokeMiterlimit: props.strokeMiterlimit || 4