Skip to content
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

SVG rendering support #50

Open
mandrade2 opened this issue Feb 13, 2023 · 0 comments
Open

SVG rendering support #50

mandrade2 opened this issue Feb 13, 2023 · 0 comments

Comments

@mandrade2
Copy link

Hey there! I'm using this package for a small project and I realized you render images with the react-native Image component which does not support SVG files. I made some small changes to support SVG uri's with react-native-svg. I tried opening a PR but couldn't. Is this something you would like to add to the package? I would need write permissions then.

Let me know what you think! Here's the proposed diff.

diff --git a/rules.js b/rules.js
index 789b67f..faa5ba2 100644
--- a/rules.js
+++ b/rules.js
@@ -1,5 +1,5 @@
 import React from 'react';
-
+import { SvgUri } from 'react-native-svg';
 import {
   Image,
   Text,
@@ -141,12 +141,20 @@ module.exports = function (styles, opts = {}) {
       react: function (node, output, {...state}) {
         var imageParam = opts.imageParam ? opts.imageParam : '';
         var target = node.target + imageParam;
-        var image = React.createElement(Image, {
-          key: state.key,
-          // resizeMode: 'contain',
-          source: {uri: target},
-          style: styles.image,
-        });
+        var image
+        if (target.match(/.*\.svg(\?.*)?$/)) {
+          image = React.createElement(SvgUri, {
+            key: state.key,
+            uri: target,
+            style: styles.image,
+          });
+        } else{
+          image = React.createElement(Image, {
+            key: state.key,
+            source: {uri: target},
+            style: styles.image,
+          });
+        }
         if (enableLightBox) {
           return React.createElement(Lightbox, {
             activeProps: styles.imageBox,

The only remaining thing other than this would be adding the dependency to the package.json and the lock file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant