Skip to content

Commit

Permalink
Merge pull request vault-development#80 from gre/onLoad
Browse files Browse the repository at this point in the history
add onLoad prop
  • Loading branch information
matc4 authored Jun 10, 2018
2 parents dbd6f52 + a29d3a8 commit 7dc8dee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
5 changes: 5 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ interface SvgUriProps {
*/
fill?: string

/**
* Invoked when load completes successfully.
*/
onLoad?: Function

/**
* Fill the entire svg element with same color
*/
Expand Down
19 changes: 13 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,28 +125,34 @@ class SvgUri extends Component{
this.isComponentMounted = false
}

async fetchSVGData(uri){
let responseXML = null;
async fetchSVGData(uri) {
let responseXML = null, error = null;
try {
const response = await fetch(uri);
responseXML = await response.text();
} catch(e) {
error = e;
console.error("ERROR SVG", e);
} finally {
if (this.isComponentMounted) {
this.setState({svgXmlData:responseXML});
this.setState({ svgXmlData: responseXML }, () => {
const { onLoad } = this.props;
if (onLoad && !error) {
onLoad();
}
});
}
}

return responseXML;
}
// Remove empty strings from children array

// Remove empty strings from children array
trimElementChilden(children) {
for (child of children) {
if (typeof child === 'string') {
if (child.trim.length === 0)
children.splice(children.indexOf(child), 1);
children.splice(children.indexOf(child), 1);
}
}
}
Expand Down Expand Up @@ -308,6 +314,7 @@ SvgUri.propTypes = {
svgXmlData: PropTypes.string,
source: PropTypes.any,
fill: PropTypes.string,
onLoad: PropTypes.func,
fillAll: PropTypes.bool
}

Expand Down

0 comments on commit 7dc8dee

Please sign in to comment.