mirror of
https://github.com/zoriya/react-native-svg.git
synced 2025-12-22 15:15:12 +00:00
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()`.
24 lines
633 B
JavaScript
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;
|
|
}
|
|
}
|