File tree Expand file tree Collapse file tree 2 files changed +31
-6
lines changed Expand file tree Collapse file tree 2 files changed +31
-6
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,9 @@ function getSDK() {
1111 return SDK_INT ;
1212}
1313function getSVG ( src : string | ImageAsset | File ) {
14+ if ( ! src ) {
15+ return null ;
16+ }
1417 let imagePath : string ;
1518 if ( src instanceof File ) {
1619 return com . caverock . androidsvg . SVG . getFromInputStream ( new java . io . FileInputStream ( new java . io . File ( src . path ) ) ) ;
@@ -402,12 +405,20 @@ export class SVGView extends SVGViewBase {
402405 }
403406 async handleSrc ( src ) {
404407 if ( src instanceof Promise ) {
405- this . handleSrc ( await src ) ;
408+ try {
409+ this . handleSrc ( await src ) ;
410+ } catch ( error ) {
411+ this . handleSrc ( null ) ;
412+ }
406413 return ;
407414 } else if ( typeof src === 'function' ) {
408- const newSrc = src ( ) ;
415+ let newSrc = src ( ) ;
409416 if ( newSrc instanceof Promise ) {
410- await newSrc ;
417+ try {
418+ await newSrc ;
419+ } catch ( error ) {
420+ newSrc = null ;
421+ }
411422 }
412423 this . handleSrc ( newSrc ) ;
413424 return ;
Original file line number Diff line number Diff line change @@ -21,6 +21,9 @@ function getUIImageScaleType(scaleType: string) {
2121
2222let bgdImagePaint : Paint ;
2323function getRenderer ( src : string | ImageAsset | File ) {
24+ if ( ! src ) {
25+ return null ;
26+ }
2427 let imagePath : string ;
2528 if ( src instanceof File ) {
2629 return SVGRenderer . alloc ( ) . initWithInputStream ( NSInputStream . alloc ( ) . initWithFileAtPath ( src . path ) ) ;
@@ -45,6 +48,9 @@ function getRenderer(src: string | ImageAsset | File) {
4548 return SVGRenderer . alloc ( ) . initWithString ( imagePath ) ;
4649}
4750function getSVGKImage ( src : string | ImageAsset | File ) {
51+ if ( ! src ) {
52+ return null ;
53+ }
4854 let imagePath : string ;
4955 if ( src instanceof File ) {
5056 return SVGKImage . alloc ( ) . initWithData ( NSData . alloc ( ) . initWithContentsOfFile ( src . path ) ) ;
@@ -322,12 +328,20 @@ export class SVGView extends SVGViewBase {
322328 }
323329 async handleSrc ( src ) {
324330 if ( src instanceof Promise ) {
325- this . handleSrc ( await src ) ;
331+ try {
332+ this . handleSrc ( await src ) ;
333+ } catch ( error ) {
334+ this . handleSrc ( null ) ;
335+ }
326336 return ;
327337 } else if ( typeof src === 'function' ) {
328- const newSrc = src ( ) ;
338+ let newSrc = src ( ) ;
329339 if ( newSrc instanceof Promise ) {
330- await newSrc ;
340+ try {
341+ await newSrc ;
342+ } catch ( error ) {
343+ newSrc = null ;
344+ }
331345 }
332346 this . handleSrc ( newSrc ) ;
333347 return ;
You can’t perform that action at this time.
0 commit comments