Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6211

Is it possible to get svg height?

$
0
0

I am using react-native-svg npm to load svg file from link in my react-native app. The problem I have is, that if you want to draw svg file you need to provide height, which can later not match the image height. I am loading svg with:

<SvgCssUri
    style={{width: imageWidth, height: 176}}
    key={Math.random()}
    uri={source}
/>

But would like to load it the same way as I am doing this on images:

export function OnlineImage({source, imageWidth}){
const [imgHeight, setImgHeight] = useState(0);

useEffect(() => {
   Image.getSize(source, (width, height) => {
       setImgHeight(height * (imageWidth / width))
   }, null);
}, [])

return(
   <Image
      style={{width: imageWidth, height: imgHeight}}
      source={{uri: source}}
      key={Math.random()}
  />);
}

Does anyone know any solution?

Or does anyone know a way to save a svg into variable to read its dimensions out of it, so that I could later use it to calculate height?


Viewing all articles
Browse latest Browse all 6211

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>