-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SvgUri example as given in README.md crashes in Expo Web #1742
Comments
I have the same issue. Took forever to track here. @raarts Have you found any workaround? And can you explain what you mean by: |
I tried to show a list of remote images using Later on I found out that if react-native-svg is installed the Image component will support svg. So, that's what I ended up doing. |
I have react-native-svg installed but Image component still doesn't render svg images. Did you still have to This is my Image component:
Any idea why it's not working? |
No, I have no idea why it's not working, but are you sure you use uri properly? Mine is a http:// URL. |
Mine is https:// URL. Yes, it's corrent, I can see the SVG in DevTools inspect, when viewing in Expo Web:
There's no error, it just doesn't show anything. When viewing in Expo iOS, it gives console warning: Are you sure all you had to do is install react-native-svg for Image component to be able to accept SVG? |
This is how I do it:
I'm pretty sure I only needed to install react-native-svg. |
Hi everyone, any idea when it is going to be fixed? |
I have the same bug. The only solution to display SVGs is either to use react-native |
Same issues here, anybody making progress on this? |
Same issue here. |
Same issues here, anybody making progress on this? |
Same issue |
Here is a very quick fix that I have hacked together. There is probably a better way to do it. Inside of export async function fetchText(uri) {
const response = await fetch(uri);
if (response.ok || response.status === 0 && uri.startsWith('file://')) {
return await response.text();
}
throw new Error(`Fetching ${uri} failed with status ${response.status}`);
}
export function SvgUri(props) {
const { onError, uri, onLoad, fallback } = props;
const [xml, setXml] = React.useState(null);
const [isError, setIsError] = React.useState(false);
React.useEffect(() => {
uri
? fetchText(uri)
.then((data) => {
setXml(data);
isError && setIsError(false);
onLoad?.();
})
.catch((e) => {
onError(e);
setIsError(true);
})
: setXml(null);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [onError, uri, onLoad]);
if (isError) {
return fallback ?? null;
}
if (!xml) {
return fallback ?? null;
}
const encoded = encodeSvg(xml);
return createElement("img", { src: "data:image/svg+xml," + encoded });
} I have placed it after the function You should save your patch with |
…1916) # Summary **What issues does the pull request solve? Please tag them so that they will get automatically closed once the PR is merged** When utilizing with `react-native-web`: SvgXml and SvgUri are not exported in the `src/ReactNativeSVG.web.ts` extension. The logic for SvgXml and SvgUri do not have native dependencies, so they are safe to consume on web. Issues: - #1279 - #1742 **What is the feature? (if applicable)** Add SvgXml and SvgUri as consumable exports for `react-native-web` **How did you implement the solution?** Extract `tags` to shapes map into separate `tags.tsx` file, where native shape elements and web shape elements can be provided to their respective envs. **What areas of the library does it impact?** `src` directory ## Test Plan Demonstrate the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes UI. ### What's required for testing (prerequisites)? n/a ### What are the steps to reproduce (after prerequisites)? n/a ## Compatibility | OS | Implemented | | ------- | :---------: | | iOS | ✅ | | Android | ✅ | ## Checklist <!-- Check completed item, when applicable, via: [X] --> - [x] I have tested this on a device and a simulator - [x] I added documentation in `README.md` - [x] I updated the typed files (typescript) - [ ] I added a test for the API in the `__tests__` folder --------- Co-authored-by: bohdanprog <[email protected]>
Hello @airowe @raarts @tmountain,
Thank you. |
Bug
I created a fresh expo app using
expo init app-simple
using the Typescript template. Added the SvgUri example.Resulted in the following error in my console:
(I have to add, the standard Expo component supports svg if you install react-native-svg. If not, it will skip svg files without warning.)
Environment info
Run
react-native info
in your terminal and copy the results here. Also, include the precise version number of this library that you are using in the projectReact native info output:
Library version: 12.1.1 (preferred by expo install, but same thing happend with 12.3.0)
Steps To Reproduce
Issues without reproduction steps or code are likely to stall.
Describe what you expected to happen:
I was expecting the app to show Homer. But it crashed and showed the above error instead.
The text was updated successfully, but these errors were encountered: