Comments (10)
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.
style
, opacity
,viewbox
and preserveAspectRatio
Svg element is based on ART`s Surface element
from react-native-svg.
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.
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.
I see, but is there a way to make the height and width of the svg flexible?
from react-native-svg.
@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.
After 2.0.0 you can use flex layout on Svg element.
And other props owned by View elements.
from react-native-svg.
@magicismight any ETA on 2.0.0?
from react-native-svg.
I tried not setting width or height and got error "width and height must be > 0"at Bitmap.java:969.
from react-native-svg.
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)
- Svg Image pointerEvents="none" not working on Android
- Invalid `RNSVG.podspec` file: undefined method `visionos' for #<Pod::Specification name="RNSVG">. HOT 11
- Invariant Violation: requireNativeComponent: "RNSVGPath" was not found in the UIManager. HOT 2
- Fatal Exception: java.lang.Error Invalid number formating character 'N' HOT 2
- SvgUri can not load some of the svgs in both android and ios
- Animating the strokeDashArray prop of an animated Path crashes running on the Android Simulator
- <Text /> with PanResponder only works if you click exactly on the letters
- Failed parsing SvgCssUri for first time, after reopening app it appears
- Xlinkhref only work on web does not work on ios and android (the color did not get inherited ) HOT 2
- React native web + vitest issue - Cannot use import statement outside a module HOT 4
- fetchText method error : TypeError: Cannot read property 'prototype' of undefined when trying to call svg from uri
- HTML entities contained in an XML string are not decoded by the SvgXml component
- Path not rendering correctly
- How to center Text along a path?
- React Native SVG stroke-width bug on expo web.
- SVG image not import in React native
- ForeignObject works with panResponder? HOT 1
- Why is `err` exported?
- stroke-width default value must be 1
- Error "ViewPropTypes" undefined in svg.js file
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-svg.