vault-development / react-native-svg-uri

Render SVG images in React Native from an URL or static file
850 stars 334 forks source link

Fill in SVG without fill tag #157

Open nikmedoed opened 5 years ago

nikmedoed commented 5 years ago

Hi, your component ignore fill in SVG nodes without fill tag. I use flaticon's SVG without fill tag, for example: <path d="M299.4,328.6c0,24.5,20,44.5,44.5,44.5s44.5-20,44.5-44.5s-20-44.5-44.5-44.5S299.4,304.1,299.4,328.6z M320.6,328.6c0-12.9,10.5-23.4,23.4-23.4s23.4,10.5,23.4,23.4S356.9,352,344,352S320.6,341.5,320.6,328.6z"/>

I try to understand how to fix your code, but faster use dirty hack:

const componentAtts =  Array.from(attributes)
      .map(utils.camelCaseNodeName)
      .map(utils.removePixelsFromNodeValue)
      .filter(utils.getEnabledAttributes(enabledAttributes.concat(COMMON_ATTS)))
      .reduce((acc, {nodeName, nodeValue}) => {
        acc[nodeName] = (this.state.fill && nodeName === 'fill' && nodeValue !== 'none') ? this.state.fill : nodeValue

        if (this.props.fillAll) {acc['fill'] = this.state.fill}

        return acc
      }, {});

Can you fix it normally?