NativeScript icon indicating copy to clipboard operation
NativeScript copied to clipboard

Support for .SVG file format

Open PanayotCankov opened this issue 10 years ago • 43 comments

There are existing libraries such as:

These can handle .SVG to some extent. Since they will increase the size of the core modules, but won't be frequently used, they are a good candidate for an optionally installed nativescript ui-plugin.


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

PanayotCankov avatar Oct 15 '15 05:10 PanayotCankov

I should add for anyone who is up for doing this I have a blog post on how to create a plugin for both iOS and android from a third party library. http://fluentreports.com/blog/?p=167 that should be very helpful in addition to the two resource that @PanayotCankov listed.

NathanaelA avatar Jan 18 '16 17:01 NathanaelA

@PanayotCankov @NathanaelA I do not agree that it would only be "rarely used" and must not be included in the central codebase for that reason. I think fairly healthy apps could use this absolutely all over, as the central tool for display resolution independence, see https://groups.google.com/forum/#!topic/nativescript/-yVyKT0159I for discussion.

Next question then is how it can be implemented the most easily in the respective target environment (iOS, Android and Windows Phone) - is there some SVG to Image/image-background rendering facility, or would native "SVG"/vector components need to be used,

What do you say?

mike-ense avatar Jan 31 '16 14:01 mike-ense

@PanayotCankov @NathanaelA , any thoughts re. relevance? And a followup question: Do both Android and iOS have good builtin native SVG/vector display facilities, or SVG to bitmap rendering?

mike-ense avatar Feb 02 '16 12:02 mike-ense

@mike-ense I'm personally with @PanayotCankov; I don't think this is a core feature. It would work really well as a plugin and @PanayotCankov has linked to several that could be used as a plugin. As for built in; to my knowledge neither have any built in support in the actual devices.

NathanaelA avatar Feb 02 '16 16:02 NathanaelA

Lacking SVG support is the reason I'm forced to limit NativeScript use. A plugin is better, but additional issues arise from plugin's use. I hope to see SVG support added, because I'm a big supporter of NativeScript, and though I recommend NativeScript all the time, I'm unable to use NativeScript for most of my work. (Thank you for the open discussion.)

WombatWorks avatar Feb 02 '16 19:02 WombatWorks

@WombatWorks why exactly would a plugin have issues? Several of the plugins are totally integrated into the system. For example, my sqlite plugin; even if it was move into core it wouldn't be written any differently nor have any additional hooks. The current project I'm working on I easily integrated Picasso on the android side and it behaves exactly as if it was totally part of the native system. I even created a property (works both in JS and in the Declarative UI XML) on the image; and Picasso then downloads the image and assigns it to that image in declarative UI. So my code is <Image url="{{imagename}}"/> and It is used in basically a list view; so it is constantly downloading/caching images. :-D Doing the same thing with a SVG plugin should be trivial also. I can't speak for the NativeScript team on if they have any intention of doing it, but with my blog posts; you should be able to build a plugin on both iOS and Android fairly quickly. If you don't want to build one; then place a bounty -- several contract developers on the forums.

I should also say my picasso integration does not actually modify anything in the core js code, so it is not upgrade sensitive and I can easily upgrade to v1.6+ when the new versions comes out. You just have to know how to structure your code and tie in to the proper places in the system to easily extend it.

NathanaelA avatar Feb 02 '16 21:02 NathanaelA

Hello,

@WombatWorks could you elaborate on use-cases you have? That would be helpful. I've been a front end developer for several years and from my experience vector graphics are not always better than a plain jpeg/png. Sometimes high fidelity vectors can be more CPU intensive than decoding a PNG.

Also this issue was placed to separate displaying SVG files from using SVG elements directly in the {N} UI markup (read integrated in the core modules).

@mike-ense Writing a plugin that uses the before mentioned libraries is supposed to be trivial in {N}. If it is not please list issues you have so we can polish our framework further.

As for relevance we have the following background in our marketplace demo that uses huge PNG instead of just drawing several vector lines, so if I could use vector graphics there I would.

The core team frequently considers voting and SVG is falling behind, you could up-vote SVG here, it is on 26th place or something..

PanayotCankov avatar Feb 03 '16 07:02 PanayotCankov

Hi Guys, I come up with this plug-in for NativeScript to support SVG files. It still in alpha, so the development continues, but you can help me out testing or with PR. It is for IOS and Android. Please report any issue you find.

The idea is use it in the same way you use the Image-source module.

https://github.com/peoplewareDo/nativescript-svg

victorsosa avatar May 08 '16 19:05 victorsosa

Hey @victorsosa,

Great work! Let's use your repo for issues, suggestions, etc. I'm closing this thread.

enchev avatar May 09 '16 13:05 enchev

The package noted here does not work with modern versions of Nativescript and was last updated 8 months ago. Should this issue be reconsidered?

bufke avatar Feb 21 '18 15:02 bufke

+1

noomieware avatar Mar 09 '18 11:03 noomieware

I think SVG support is VERY important in modern apps (especially cross platforms ones) and this should be part of the core Nativescript offer so it can be properly maintained and updated...I would reopen this one

demetrio812 avatar May 18 '18 09:05 demetrio812

@bufke if you are referring to https://github.com/peoplewareDo/nativescript-svg it does still work, and is "usable".

I say that within quotation marks as it's No Support list is bigger than the list of supported functionality. I believe this issue should be reopened as SVG support feels like core functionality considering how prevalent they are within modern web development, and recreating the functionality surrounding them is close to impossible with the alternative image formats available.

Gitelaus avatar Sep 04 '18 11:09 Gitelaus

When I looked at that project, it didn't work at all with the latest NS. Seems like it got some updates in Aug so I will check it out. Looking at the :+1:'s it seems I am not alone in having trouble.

I agree that it feels like a core feature and is something a web developer is used to having supported. When porting an existing web SPA to have a NS version we had to convert all SVG's to various sized image assets which is not ideal. At the time at least it didn't seem viable using svg with NS. That said react-native also does not have core svg support.

bufke avatar Sep 04 '18 15:09 bufke

@enchev @gitelaus under what context can this issue get re-opened? SVG is absolutely as essential as support for raster images.

This is a modern framework for building cross platform mobile applications.

By it's very conception, it should support various resolutions and SVG is the one graphic format built to scale.

drewcovi avatar Nov 06 '18 19:11 drewcovi

@bufke it may be working, but only barely.

@victorsosa do you still maintain the repo? seems issues are left languishing.

drewcovi avatar Nov 06 '18 19:11 drewcovi

Yes! What would it take to reopen this issue?

stevenspiel avatar Jan 11 '19 21:01 stevenspiel

Reopening the issue and marking this one as a feature.

NickIliev avatar Jan 14 '19 09:01 NickIliev

Zomg!

drewcovi avatar Jan 14 '19 14:01 drewcovi

SVG support would be perfect. No more fiddling around with SVG -> PNG conversion and trying to guess what size could be perfect for what screen size and resolution.

The ideal solution is NativeScript + X aware. Shouldn't care much if you use Angular, Vue, Svelte, or React.

ghost avatar Dec 27 '19 22:12 ghost

This would be a great feature indeed! Have there been any updated plans on this lately?

oneWaveAdrian avatar Apr 21 '20 15:04 oneWaveAdrian

Please svg asap!

rgr19 avatar Apr 24 '20 10:04 rgr19

i am also currently working on a project that uses a hoard of iconography. svg support would indeed be very helpful

rizosamuel avatar Jul 17 '20 13:07 rizosamuel

@rizosamuel I started adding svg support to the canvas plugin

triniwiz avatar Jul 17 '20 17:07 triniwiz

Looking around the landscape today, I couldn't find any way to add svg support in NS 7.

  • nativescript-svg has not worked for years as far as I can tell. I can't get past Could not find com.pixplicity.sharp:library:1.0.2 but there's numerous upstream issues reporting it doesn't work. https://github.com/peoplewareDo/nativescript-svg/issues/50
  • @teammaestro/nativescript-svg is a 3 year old fork that did work for me before NS 7 but no longer works. SVG's just don't show up once upgrading to 7. I'm mostly sure it's not a webpack copy problem as the latest vanilla webpack config copies all assets.

Someone says they got simplistic svgs working as a font - if considering this. I'd probably recommend finding a new job or hobby over this...

bufke avatar Oct 18 '20 18:10 bufke

Our designers now prefer to work with web developers rather than the mobile developers simply because they can integrate the produced SVG artifacts with almost no effort.

A migration to React Native or pure native apps would be conceivable or customers who pay more because it takes longer to 'rebuild' SVG artifacts in NS apps.

ghost avatar Oct 18 '20 19:10 ghost

Please note; the new https://github.com/NativeScript/canvas, not sure if Osei can use any help; but I know he has been working on getting full SVG support into the plugin. ;-)

NathanaelA avatar Oct 18 '20 19:10 NathanaelA

Impossible to find for non-NS-core members as Canvas as no up-to-date Readme, description, or useful commit-history.

ghost avatar Oct 19 '20 08:10 ghost

Our designers now prefer to work with web developers rather than the mobile developers simply because they can integrate the produced SVG artifacts with almost no effort.

A migration to React Native or pure native apps would be conceivable or customers who pay more because it takes longer to 'rebuild' SVG artifacts in NS apps.

Scripted asset generation from SVG to appropriately sized raster graphics for resources is reasonably trivial to do in the meantime, for both iOS and Android.

This can also be tied into the webpack process too if you want to have an easy way to include the graphics you need without having the checked into your repositories etc.

Impossible to find for non-NS-core members as Canvas as no up-to-date Readme, description, or useful commit-history.

There are 3 applications demonstrating usage that can modified for your test cases: https://github.com/NativeScript/canvas/tree/master/apps

Surely there's something there that'll help :)

Codex- avatar Oct 19 '20 10:10 Codex-

I won't start generating thousand of PNGs as they need generating for several display-resolutions and screen-sizes. And if our users start using iOS or Android accessibility features like full-screen zoom or Magnifiers, PNG pixelates a lot when the zoom factor is uneven and larger than 1. I'm somewhat sad receiving such a recommendation in 2020.

Canvas SVG is the only option so far unless decisions lead to React Native or pure native apps.

ghost avatar Oct 19 '20 11:10 ghost