question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Svg does not respect container width/height

See original GitHub issue

Svg renders at full size always and does not scale down to fit the container size. In this case below, svg cannot be seen because it has rendered outside 100x100 area.

 <Canvas style={{height: 100, width: 100}}>
      {source && (
        <ImageSVG
          height={100}
          width={100}
          x={0}
          y={0}
          source={source}
        />
      )}
    </Canvas>

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
chrfalchcommented, Jan 20, 2022

Couldn’t agree more. React Native Skia should be a foundation for others to extend on - and the SVG rendering looks like a very good candidate for building a library.

0reactions
ammarahm-edcommented, Jan 20, 2022

@chrfalch I completely agree with you on this. This will require parsing the dom on JS side or Native then resizing according to the container with so the svg can fit properly. This will require extra maintainence and also increase the bundle size when if add any html parser to do this.

But the problem is that the usefulness of svg support becomes very limited without this since mobile devices are small and will require scaling things down like images and svgs.

One way is to not do it yourself from ground up but instead use an external dependency to handle resizing the svg on JS side.

Or hope that someone makes a library that uses react-native-skia to render svgs with resizing support. That you can you focus on the core parts.

I think that this library is more like a canvas in browser that gives you what is needed to build what you want. But it really depends on you, the devs. It can be an all in one solution for graphics too.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I make an svg scale with its parent container?
Notice how I set only width, no height. I set it to 100% so it fills the container it is in. This is...
Read more >
How to make an svg scale with its parent container
The SVG element occupies 100% width of the parent container and its height is auto-adjusted depending on screen size. We use viewBox to...
Read more >
How to Scale SVG | CSS-Tricks
SVG images, in contrast, can be drawn at any pixel size, so they don't need a clearly defined height or width. And they...
Read more >
SVG in <img> without viewBox and with CSS height/width ...
> I'd expect height and width on an <iframe> to cause the contents to become > scrollable if they don't fit, whether it...
Read more >
SVG sizing - Google Docs
With user agent style 100% width/height the size would be the same as long as the container has auto-height (and the SVG doesn't...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found