peoplewareDo / nativescript-svg

Nativescript plugin - support for .SVG file format
Other
70 stars 55 forks source link

Angular7 Android doesn't work #42

Open mosilver opened 5 years ago

mosilver commented 5 years ago

Is that plugin compactible with newest angular (7) and nativeScript (5) ?

I have created a new angular template project with nativescript CLI, added this plugin and I can't force it work, in general I have problem with path to file source, but using the same path for png file it's fine

By default with angular shared code project we should put all resources in src/assets

<StackLayout class="page">
   <SVGImage src="~/assets/images/nativescript.svg" height="100" width="100"></SVGImage>
</StackLayout>

JS: ERROR Error: java.io.FileNotFoundException: /data/data/org.nativescript.nowy/files/app/assets/images/nativescript.svg (No such file or directory)

I tried as well images folder in root of src, in app folder and so on... :

<StackLayout class="page">
   <SVGImage src="~/images/nativescript.svg" height="100" width="100"></SVGImage>
</StackLayout>

JS: ERROR Error: java.io.FileNotFoundException: /data/data/org.nativescript.nowy/files/app/images/nativescript.svg (No such file or directory)

I tried to use platform resources folder:

<StackLayout class="page">
    <SVGImage src="res://nativescript.svg" height="100" width="100"></SVGImage>
</StackLayout>

then no error but no image as well, even in official githab version with angular 4

When trying to load external resources:

<StackLayout class="page">
    <SVGImage src="https://svgshare.com/i/BjR.svg" height="100" width="100"></SVGImage>
</StackLayout>

JS: ERROR Error: Cannot convert object to Ljava/lang/String; at index 0

ihor-lev commented 5 years ago

@mosilver: It helped for me to include svg files in webpack.config.js as assets which should be copied to out dir. Here it is:

      // Copy assets to out dir. Add your own globs as needed.
      new CopyWebpackPlugin([
        {from: "fonts/**"},
        {from: "**/*.jpg"},
        {from: "**/*.png"},
        {from: "**/*.svg"},
      ], {ignore: [`${relative(appPath, appResourcesFullPath)}/**`]}),

But I have started using the fork https://github.com/TeamHive/nativescript-svg which is installed as tns plugin add "@teammaestro/nativescript-svg". This fork is using more fresh SVG library for android.