Files
react-native-svg/lib/extract/extractBrush.js
James Ide 235e132baf Update "color" dep to 2.x to fix RN minifier bug
There's a bug with the version of UglifyJS that RN/Metro uses which causes an error about "e.length" inside of "color" that was fixed in 2.x. One change to "color" is that `rgbaArray()` was removed and now the call is `rgb().array()`.
2017-11-09 12:28:13 -08:00

24 lines
633 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 c = Color(colorOrBrush).rgb().array();
return [0, c[0] / 255, c[1] / 255, c[2] / 255, c[3]];
}
} catch (err) {
console.warn(`"${colorOrBrush}" is not a valid color or brush`);
return null;
}
}