@@ -125,16 +125,22 @@ class SvgUri extends Component{
125
125
this . isComponentMounted = false
126
126
}
127
127
128
- async fetchSVGData ( uri ) {
129
- let responseXML = null ;
128
+ async fetchSVGData ( uri ) {
129
+ let responseXML = null , error = null ;
130
130
try {
131
131
const response = await fetch ( uri ) ;
132
132
responseXML = await response . text ( ) ;
133
133
} catch ( e ) {
134
+ error = e ;
134
135
console . error ( "ERROR SVG" , e ) ;
135
136
} finally {
136
137
if ( this . isComponentMounted ) {
137
- this . setState ( { svgXmlData :responseXML } ) ;
138
+ this . setState ( { svgXmlData : responseXML } , ( ) => {
139
+ const { onLoad } = this . props ;
140
+ if ( onLoad && ! error ) {
141
+ onLoad ( ) ;
142
+ }
143
+ } ) ;
138
144
}
139
145
}
140
146
@@ -144,8 +150,8 @@ class SvgUri extends Component{
144
150
// Remove empty strings from children array
145
151
trimElementChilden ( children ) {
146
152
for ( child of children ) {
147
- if ( typeof child === 'string' ) {
148
- if ( child . trim ( ) . length === 0 )
153
+ if ( typeof child === 'string' ) {
154
+ if ( child . trim ( ) . length === 0 )
149
155
children . splice ( children . indexOf ( child ) , 1 ) ;
150
156
}
151
157
}
@@ -217,6 +223,11 @@ class SvgUri extends Component{
217
223
218
224
obtainComponentAtts ( { attributes} , enabledAttributes ) {
219
225
const styleAtts = { } ;
226
+
227
+ if ( this . state . fill && this . props . fillAll ) {
228
+ styleAtts . fill = this . state . fill ;
229
+ }
230
+
220
231
Array . from ( attributes ) . forEach ( ( { nodeName, nodeValue} ) => {
221
232
Object . assign ( styleAtts , utils . transformStyle ( {
222
233
nodeName,
@@ -241,7 +252,7 @@ class SvgUri extends Component{
241
252
inspectNode ( node ) {
242
253
// Only process accepted elements
243
254
if ( ! ACCEPTED_SVG_ELEMENTS . includes ( node . nodeName ) ) {
244
- return null ;
255
+ return ( < View /> ) ;
245
256
}
246
257
247
258
// Process the xml node
@@ -275,7 +286,7 @@ class SvgUri extends Component{
275
286
const inputSVG = this . state . svgXmlData . substring (
276
287
this . state . svgXmlData . indexOf ( "<svg " ) ,
277
288
( this . state . svgXmlData . indexOf ( "</svg>" ) + 6 )
278
- ) ;
289
+ ) . replace ( / < ! - ( . * ? ) - > / g , '' ) ;
279
290
280
291
const doc = new xmldom . DOMParser ( ) . parseFromString ( inputSVG ) ;
281
292
@@ -300,6 +311,8 @@ SvgUri.propTypes = {
300
311
svgXmlData : PropTypes . string ,
301
312
source : PropTypes . any ,
302
313
fill : PropTypes . string ,
314
+ onLoad : PropTypes . func ,
315
+ fillAll : PropTypes . bool
303
316
}
304
317
305
318
module . exports = SvgUri ;
0 commit comments