Code Monkey home page Code Monkey logo

Comments (10)

ajoshdee avatar ajoshdee commented on May 2, 2024 7

Can I create SVG elements without specifying width and height? The size of the parent view will depend on the content of the child view.

from react-native-svg.

magicismight avatar magicismight commented on May 2, 2024

style, opacity,viewbox and preserveAspectRatio

Svg element is based on ART`s Surface element

from react-native-svg.

ajoshdee avatar ajoshdee commented on May 2, 2024

Is it possible to get the dimensions of the SVG? I want my element for ex: Circle, to be relative to the size of the SVG container

from react-native-svg.

magicismight avatar magicismight commented on May 2, 2024

You can set with and height of Svg by using variables.

let height = 100;
let width = 100;

<Svg height={height} width={width}>
    <Circle x={width * 0.1} y={height * 0.2} r={width * 0.5} />
</Svg>

from react-native-svg.

ajoshdee avatar ajoshdee commented on May 2, 2024

I see, but is there a way to make the height and width of the svg flexible?

from react-native-svg.

LightningK0ala avatar LightningK0ala commented on May 2, 2024

@ajoshdee For some reason my Svg component doesn't respond to a changing width / height value when using the onLayout prop of a parent View to update the width / height dynamically. But the inner components (i.e. the Circle in your example) will respond to those layout changes.

So what I did was to use this:

var SCREEN_WIDTH = require('Dimensions').get('window').width;
var SCREEN_HEIGHT = require('Dimensions').get('window').height;

Those values will give you ample space for the SVG container.
Now the inner elements can just be scaled according to your View layout.

I hope that makes some sense...

from react-native-svg.

magicismight avatar magicismight commented on May 2, 2024

After 2.0.0 you can use flex layout on Svg element.
And other props owned by View elements.

from react-native-svg.

felixakiragreen avatar felixakiragreen commented on May 2, 2024

@magicismight any ETA on 2.0.0?

from react-native-svg.

adrianboimvaser avatar adrianboimvaser commented on May 2, 2024

I tried not setting width or height and got error "width and height must be > 0"at Bitmap.java:969.

from react-native-svg.

kriskate avatar kriskate commented on May 2, 2024

Ended up here having the same problem (width/ height taken through state from onLayout results in not working).

I did the following:

    const {width, height } = this.state
[...]
    <Svg style={{position: 'absolute'}} 
        width={width} height={height}
        viewBox={`0 0 ${width} ${height}`}
    >

It works without position: absolute, but that how I use it.

from react-native-svg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.