How to center a react native svg with flex? - react-native

How would I use flex to center an svg within a View in react native?
Here is an expo snack that centers an svg by its origin parameters.
Do I need to hardcode origin parameters, place the svg in a View with a flex property, and then export it as a component?
Does svg care about flex?
A related but distinct SO question:
How to center an SVG in React Native?
-> From this answer, should I convert my shape-based svg into a path xml tag? That doesn't seem like the right answer here.
I would rather define svgs inline than import svg files.

Related

React-native - Pulsating Image / SVG

Is it possible to pulsating a SVG in a Component? And how can i do this?
I found some packages but pulsating a circle, i want to pulsating a bag (SVG)
Yes, it's possible. react-native-svg allows you to import SVGs (with some setup), or you can use its primitives to convert an SVG to RN components. Then to animate it, use React Native's Animated API. The fade in/out example on the API page can be easily adapted to make a pulsing animation.

Using CSS dimensions in react-native

In normal css, dimensions like px, %, rem etc. works perfectly. But in react native, it throws an error.
Are there any possible ways to use these dimensions directly in react-native ?
REMs are a way of setting font-sizes based on the font-size of the root HTML element.
react native is purely works on pixels. Different mobile screens have different pixel ratio .
pixelRatio documentation in react native
if you want text normalization in react native
use my custom function in my open source project.
Suppose you want the width to be 50% of the View so you can do <View style={{width:'50%'}} /> .
Hope its clear. Feel free for doubts.

Is it possible to add onPress event to svg graphic which was loaded from file in React Native?

In my React Native application I need to load a svg graphic from a file and add onPress events to suitable svg elements based on element ids. I want to ask if it is possible in React Native?
To add the svg file I plan to use the solution form react-native-svg (https://www.npmjs.com/package/react-native-svg#use-with-svg-files).

SVG as background image in React Native

I use react-native-svg to insert SVG images into my React Native app.
I'm currently replacing my pngs by svgs because of the blurriness of most of my assets. I came to a use case where I need to replace an ImageBackground, that uses png by an SVG file. Is there a way to do this? I tried to use the image as a main component with all my elements inside but the image appears on top of everything.
You can use react-native-svg-uri
Example
<SvgUri
width="200"
height="200"
source={{uri:'http://thenewcode.com/assets/images/thumbnails/homer-simpson.svg'}}
source={require('./simpson.svg')}
/>

Want to real image is clickable but should not click the alpha background. Please suggest me how can i do this

i'm facing a problem in react native
Want to real image is clickable but should not click the alpha background. Please suggest me how can i do this.
In below image i used zIndex to placing the birds ,red color indicate the alpha area of above birdenter image description here
Unfortunately, there's no easy way to do this with React Native. The best solution I've found is by defining SVGs and using react-native-svg, which supports touch events. If you're using Expo, then it is already preinstalled and can be imported like import { Svg } from 'expo'; const { Circle, Rect } = Svg;.
Alternatively, you may be able to use a WebView (mirror) and CSS masking to achieve your desired result.