Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying external SVG image from URL in react native

Is there any package that would allow me to display SVG image loaded from external URL?

I've tried to use react-native-svg-image / react-native-svg-uri and their forks but none of those are working correctly - is there any non dead package for react-native that would do the job?

This is the sample error being thrown by svg-img-uri

<SvgUri width="24" height="24" source={{ uri: 'https://cdnjs.cloudflare.com/ajax/libs/flag-icon-css/3.3.0/flags/1x1/ad.svg' }} />
Text strings must be rendered within a <Text> component.

This error is located at:
    in RNSVGDefs (at Defs.js:8)
like image 215
Inveth Avatar asked Dec 31 '22 23:12

Inveth


1 Answers

react-native-svg now supports display svg from online uri

import { SvgUri } from 'react-native-svg';

export default () => (
  <SvgUri
    width="100%"
    height="100%"
    uri="http://demo.com/assets/your/image.svg"
  />
);

Reference https://github.com/react-native-svg/react-native-svg#use-with-content-loaded-from-uri

like image 189
gasolin Avatar answered Feb 06 '23 16:02

gasolin