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 images support #333

Open
dnicer3 opened this issue Feb 12, 2023 · 3 comments
Open

SVG images support #333

dnicer3 opened this issue Feb 12, 2023 · 3 comments

Comments

@dnicer3
Copy link

dnicer3 commented Feb 12, 2023

I have spent long time trying to implement SVG images in my Svelte Native App, however, the only really working solution from other repositories is to transfer them to PNG. I have already tried many packages like svelte-inline-svg, svelte-svg etc. I have also tried to register in app.ts and use nativescript plugins such as nativescript-svg, ui-svg and so on, but still no response. The best what I have reached is just a blank screen. Could anyone please advise a proper solution?

@FredericKarliczek
Copy link

FredericKarliczek commented Feb 26, 2023

I managed to use a SVG image with the native script plugin "@nativescript-community/ui-svg" .

  1. Install the native script plugin:
ns plugin add @nativescript-community/ui-svg
  1. Register the components in app.ts :
import { registerNativeViewElement } from 'svelte-native/dom'
import { svelteNativeNoFrame } from 'svelte-native'
import App from './App.svelte'

registerNativeViewElement("canvasSVG", () => require("@nativescript-community/ui-svg").CanvasSVG);
registerNativeViewElement("cSVG", () => require("@nativescript-community/ui-svg").SVG);
registerNativeViewElement('svgView', () => require("@nativescript-community/ui-svg").SVGView);
  1. Use new tags 'canvasSVG', 'cSVG', 'svgView':
<canvasSVG>
  <cSVG horizontalAlignment="left" src="~/assets/red_blue_squares.svg" height="100%" width="100%" stretch="aspectFit" />
</canvasSVG>

I had also to specify the width which was not specified in the example of the plugin. Hope this helps.

@dnicer3
Copy link
Author

dnicer3 commented Feb 27, 2023

@FredericKarliczek That plugin for me ismthe closest one to the solution, because I don't get errors within it. However, anyway I have an issue - it throws me "SvelteNativeDom: set attribute threw an error, attr:src on csvg: SVGKImage is not defined" error, Maybe there are some extra dependencies or extra rollup configurations?

@farfromrefug
Copy link
Collaborator

@dnicer3 you need to share the callstack for your error. also you should try with the svgView which is a simple view on which you can defined a src prop (and stretch,...) for the svg

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

3 participants