Files
react-native-svg/lib/extract/extractBrush.js
James Ide f9e774e03d Handle color parsing when alpha = 1 (#512)
The `color` library doesn't include alpha when accessing `color.rgb().array()` when the alpha value is 1. Since we always use the alpha value, make it default to 1 when parsing a color.
2017-11-23 13:47:01 -08:00

24 lines
636 B
JavaScript

import Color from 'color';
import patternReg from './patternReg';
export default function (colorOrBrush) {
if (colorOrBrush === 'none' || !colorOrBrush) {
return null;
}
try {
let matched = colorOrBrush.match(patternReg);
// brush
if (matched) {
return [1, matched[1]];
//todo:
} else { // solid color
let [r, g, b, a = 1] = Color(colorOrBrush).rgb().array();
return [0, r / 255, g / 255, b / 255, a];
}
} catch (err) {
console.warn(`"${colorOrBrush}" is not a valid color or brush`);
return null;
}
}