mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-09 09:27:20 +00:00
Fix strokeDasharray handling of odd number of length values and the 'none' value.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user