seekshiva / react-native-remote-svg

Adds support for loading svg images in React Native
MIT License
184 stars 71 forks source link

Do not require a `.svg` extension #1

Open ckknight opened 6 years ago

ckknight commented 6 years ago

As-is, if the URI does not end in .svg, then it will fallback to react-native's built-in Image implementation.

(See https://github.com/seekshiva/react-native-remote-svg/blob/master/index.js#L8)

I personally would rather handle that fallback case in my own code and only use the SvgImage, but if I were to reach in via react-native-remote-svg/SvgImage, then it no longer does the automatic resolveAssetSource.

seekshiva commented 6 years ago

@ckknight It just matches '.svg' anywhere in the string. So if you have a file named 'something.svg.png', it will wrongly get matched as svg and end up using SvgImage.

But I let it match '.svg' anywhere in the string and not just in the end, since this is actually a valid filename: https://example.com/image.svg?color-scheme=material&show-options=true

How do you propose the file type detection to work? I still haven't added supported for data uri yet.

ckknight commented 6 years ago

It can't be assumed that I have control over what the remote URL is. I need a way to be able to render a remote URL as though it were .svg even if that "magic string" is not found in the URL itself.

Ideally, it might be most appropriate to switch based on the response's Content-Type header, but that might be out-of-scope for this component.

jpschw commented 5 years ago

One of the fundamental principles of Javascript is "Don’t modify objects you don’t own". This component should not attempt to augment the Image object provided by React Native but rather be named something like SVGImage instead.