aeirola / react-native-svg-asset-plugin

Asset plugin for importing SVG images in React Native
https://www.npmjs.com/package/react-native-svg-asset-plugin
MIT License
68 stars 9 forks source link

Can this plugin be enabled only for Android/AndroidTV platform? #20

Closed dblachut-adb closed 5 years ago

dblachut-adb commented 5 years ago

Hi, I was wondering if this plugin could be enabled only in case of Android/AndroidTV platform? Maybe this can be done in metro.config.js file?

I am using this plugin because SVG assets are not supported directly in Android, but I wouldn't like to change how SVGs are used on other platforms.

Any help would be appreciated.

aeirola commented 5 years ago

The plugin itself doesn't support any platform specific configuration, and I don't think React Native nor the Metro bundler supports platform specific plugins.

What is your use case for only enabling the plugin on certain platforms? How do you expect the require('image.svg') to behave in situations where the plugin has been disabled? As far as I know, at least none of the official react native platforms support SVG by themselves.

dblachut-adb commented 5 years ago

Thank you for responding so quickly.

What is your use case for only enabling the plugin on certain platforms?

I am using this plugin to bypass the problem with svg files in Android's apk resources like this one. Since the problem occurs only on Android platform, I would like to keep iOS version unchanged.

How do you expect the require('image.svg') to behave in situations where the plugin has been disabled? As far as I know, at least none of the official react native platforms support SVG by themselves.

In general I am using SvgUri component from react-native-svg-from-uri, in which you can pass the results of require('image.svg') "normally" to source prop. The only problem is on android release version where such file cannot be added to an apk file.

So to answer your question directly: when plugin is disabled require('image.svg') would return an unchanged assetData, same as the plugin is currently doing with other asset types.

I was also thinking that maybe the metro provides some data about build type when asking the plugin for asset transformation. In this way the plugin could remain enabled but its internal logic could decide how to transform the asset based on build platform. Unfortunately I don't know nothing about metro and it's documentation seems to be a bit poor.

aeirola commented 5 years ago

Hmm, that sounds like a bit of a strange use case. I don't really see the point in using different image rendering methods on different platforms. I'd say the effort would be better spent on fixing the issues in the react-native-svg-from-uri package instead.

Alternatively, just use something else based on react-native-svg runtime rendering instead. https://github.com/kristerkari/react-native-svg-transformer looks handy.

dblachut-adb commented 5 years ago

Sure, I will give it a try although from initial research it seems that people are reporting some problems with it. Thanks for reaching out.