aeirola / react-native-svg-asset-plugin Goto Github PK
View Code? Open in Web Editor NEWAsset plugin for importing SVG images in React Native
Home Page: https://www.npmjs.com/package/react-native-svg-asset-plugin
License: MIT License
Asset plugin for importing SVG images in React Native
Home Page: https://www.npmjs.com/package/react-native-svg-asset-plugin
License: MIT License
Using a colon in the file names created here:
const outputName =
${assetData.name}:${assetData.hash};
causes issues on Windows, the PNG files are not created (instead you get empty files in the cache folder).
The plugin caches generated PNG images under .png-cache
directories adjacent to any imported SVG files. Due to metro bundler caching, the plugin retains all old versions of SVG images in the caches, meaning that the caches only grow as more changes are made to the SVG files. This can cause unnecessary disk space usage.
The command yarn react-native bundle --platform android --entry-file index.ts --bundle-output out
idles for at least a few minutes after it finished.
I found out that the following lines are responsible for this: https://github.com/aeirola/react-native-svg-asset-plugin/blob/master/src/cache.js#L63-L67
This was introduced here: https://github.com/aeirola/react-native-svg-asset-plugin/pull/49/files
When building in release mode there should be no cleanup task scheduled.
First, thanks for your library!
When building our app for iPhone in a Mac environment, the images are not rendered (the build doesn't cancel though).
The console gives the following output:
bundle: Writing bundle output to: /[...]/Build/Intermediates.noindex/ArchiveIntermediates/Integreat/BuildProductsPath/Release-iphoneos/Integreat.app/main.jsbundle
bundle: Done writing bundle output
Input buffer has corrupt header: glib: SVG has no elements
Error: Input buffer has corrupt header: glib: SVG has no elements
+ [[ false != true ]]
+ [[ ! -f /[...]/Build/Intermediates.noindex/ArchiveIntermediates/Integreat/BuildProductsPath/Release-iphoneos/Integreat.app/main.jsbundle ]]
A similar library like yours uses a workaround for this issue:
aeirola/react-native-icon-builder@c1e8262
This issue might also be related to lovell/sharp#1593.
I hope you can fix this.
Edit: I just noticed this other library is authored by you as well :D Do you think this is the same issue here?
Edit2: I just saw that you already released something 3 hours ago for this :O I'm checking this out โค๏ธ
Edit3: It does already work, thanks ๐
Stumbled upon this project,
was wondering if it works with Expo.
Followed the instructions, but haven't been able to get it to run in Expo yet.
Looking at the current configuration opens it's not possible to configure a folder from which all required SVG files will be ignored. This prevents me from using this plugin in conjunction with react-native-svg
.
Is there maybe any way to achieve this using metro configuration alone?
Thanks.
Error message: error: bundling failed: Error: vips__file_open_write: unable to open file "/path-to-file/.png-cache/file.png" for writing
unix error: Invalid argument
I couldn't use your plugin because of this error. Somehow, the plugin wasn't able to save the file.
Although I couldn't find any code for folder creation, I saw that the plugin was able to create .png-cache folder during the transformation. I found this issue that could help solving this problem, but I do know that the folder was created.
It would be nice if the generated pngs could be compressed, for example by using pngquant, to reduce the file size of the pngs.
It would be cool if this could be configurable.
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.
Occasionally changes to SVG files do not always show up in the application. This seems to occur on changes to the files, which are later reverted. Changes which produce new images are shown properly in the application.
This probably has something to do with how Metro caches the assets.
I am using the Image component to display svg, it is working normally, however I wanted to set the color, but I can't.
iOS / Xcode supports vector graphics in PDF format. In theory it would be possible to generate PDFs from source SVG images, in addition to the PNG images already generated. This would also require some way of then passing the PDF files to the image component in React Native. There is support for Hybrid app resources, but not entirely sure how it would work.
There already seems to exist https://github.com/alafr/SVG-to-PDFKit which is able to convert SVG files to PDF, so the heavy lifting is already done in some part.
I am in the scenario where I have some svg images and some jpg/png images.
When using this plugin all the svg are converted and loaded correctly, but when trying to use the png it does not work and shows a blank image.
Is it supposed to be like this?
Hye, the projects look interesting, I have a question.. does this package support svg that is coming from uri? such
https://restcountries.eu/data/mys.svg
Thanks!
React native fastimage is pretty much superior to the built in image component.
Android supports its own vector graphic format called VectorDrawable. It could be convenient if this library would also support generating vector drwable resources instead of / in addition to PNG images. VectorDrawables seem to be a subset of SVG though, so this would require some mechanism for identifying lossy conversions and warn about them or fall back to PNG images.
Also not entirely sure how to properly pass the native image resources to React Native. There is some support for Hybrid app resources in React Native. But not sure though how those should be generated and passed by an asset plugin.
There seems to already exist a library for doing the conversion at https://github.com/Ashung/svg2vectordrawable. Probably wouldn't hurt to try it out as an experimental feature.
ld: library not found for -lRNSVG
clang: error: linker command failed with exit code 1 (use -v to see invocation)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.