11

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)

2 Answers 2

31

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

Sign up to request clarification or add additional context in comments.

2 Comments

This should be the selected answer. This one worked like charm
@HabiburRahman nope, it does not work
2

The url doesnt' have any quotes around it. That might be the problem

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

5 Comments

I was asking about React-Native
There seem to be no quotes around the url
Could forgot about them but nope - that's not a problem. Can't find any working component for that - like whole react native SVG is dead everywhere.
What's it say now?
Same error - I just forgot to add brackets in my comment. They cannot solve it on bitbucket there and looks like other forked projects are failing too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.