Support
Quality
Security
License
Reuse
Coming Soon for all Libraries!
Currently covering the most popular Java, JavaScript and Python libraries. See a SAMPLE HERE.
kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
Supports most SVG elements and properties (Rect, Circle, Line, Polyline, Polygon, G ...).
Easy to convert SVG code to react-native-svg.
Installation Automatically Manually Android iOS
Troubleshooting
Opening issues
Usage Use with content loaded from uri Use with svg files Use with xml strings
Common props
Supported elements Svg Rect Circle Ellipse Line Polygon Polyline Path Text TSpan TextPath G Use Symbol Defs Image ClipPath LinearGradient RadialGradient Mask Pattern Marker ForeignObject
Touch Events
Serialize
Run example
TODO
Known issues
Installation
yarn add react-native-svg
NOTICE:
include ':react-native-svg'
project(':react-native-svg').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-svg/android')
Troubleshooting
-keep public class com.horcrux.svg.** {*;}
Opening issues
react-native info
Usage
import Svg, {
Circle,
Ellipse,
G,
Text,
TSpan,
TextPath,
Path,
Polygon,
Polyline,
Line,
Rect,
Use,
Image,
Symbol,
Defs,
LinearGradient,
RadialGradient,
Stop,
ClipPath,
Pattern,
Mask,
} from 'react-native-svg';
/* Use this if you are using Expo
import * as Svg from 'react-native-svg';
const { Circle, Rect } = Svg;
*/
import React from 'react';
import { View, StyleSheet } from 'react-native';
export default class SvgExample extends React.Component {
render() {
return (
<View
style={[
StyleSheet.absoluteFill,
{ alignItems: 'center', justifyContent: 'center' },
]}
>
<Svg height="50%" width="50%" viewBox="0 0 100 100">
<Circle
cx="50"
cy="50"
r="45"
stroke="blue"
strokeWidth="2.5"
fill="green"
/>
<Rect
x="15"
y="15"
width="70"
height="70"
stroke="red"
strokeWidth="2"
fill="yellow"
/>
</Svg>
</View>
);
}
}
Use with content loaded from uri
import * as React from 'react';
import { SvgUri } from 'react-native-svg';
export default () => (
<SvgUri
width="100%"
height="100%"
uri="http://thenewcode.com/assets/images/thumbnails/homer-simpson.svg"
/>
);
Use with svg files
const { getDefaultConfig } = require('metro-config');
module.exports = (async () => {
const {
resolver: { sourceExts, assetExts },
} = await getDefaultConfig();
return {
transformer: {
babelTransformerPath: require.resolve('react-native-svg-transformer'),
},
resolver: {
assetExts: assetExts.filter(ext => ext !== 'svg'),
sourceExts: [...sourceExts, 'svg'],
},
};
})();
Use with xml strings
import * as React from 'react';
import { SvgXml } from 'react-native-svg';
const xml = `
<svg width="32" height="32" viewBox="0 0 32 32">
<path
fill-rule="evenodd"
clip-rule="evenodd"
fill="url(#gradient)"
d="M4 0C1.79086 0 0 1.79086 0 4V28C0 30.2091 1.79086 32 4 32H28C30.2091 32 32 30.2091 32 28V4C32 1.79086 30.2091 0 28 0H4ZM17 6C17 5.44772 17.4477 5 18 5H20C20.5523 5 21 5.44772 21 6V25C21 25.5523 20.5523 26 20 26H18C17.4477 26 17 25.5523 17 25V6ZM12 11C11.4477 11 11 11.4477 11 12V25C11 25.5523 11.4477 26 12 26H14C14.5523 26 15 25.5523 15 25V12C15 11.4477 14.5523 11 14 11H12ZM6 18C5.44772 18 5 18.4477 5 19V25C5 25.5523 5.44772 26 6 26H8C8.55228 26 9 25.5523 9 25V19C9 18.4477 8.55228 18 8 18H6ZM24 14C23.4477 14 23 14.4477 23 15V25C23 25.5523 23.4477 26 24 26H26C26.5523 26 27 25.5523 27 25V15C27 14.4477 26.5523 14 26 14H24Z"
/>
<defs>
<linearGradient
id="gradient"
x1="0"
y1="0"
x2="8.46631"
y2="37.3364"
gradient-units="userSpaceOnUse">
<stop offset="0" stop-color="#FEA267" />
<stop offset="1" stop-color="#E75A4C" />
</linearGradient>
</defs>
</svg>
`;
export default () => <SvgXml xml={xml} width="100%" height="100%" />;
Supported elements:
<Svg height="100" width="100">
<Rect x="0" y="0" width="100" height="100" fill="black" />
<Circle cx="50" cy="50" r="30" fill="yellow" />
<Circle cx="40" cy="40" r="4" fill="black" />
<Circle cx="60" cy="40" r="4" fill="black" />
<Path d="M 40 60 A 10 10 0 0 0 60 60" stroke="black" />
</Svg>
Serialize
import * as React from 'react';
import { Platform, StyleSheet, TouchableOpacity } from 'react-native';
import { Svg, Rect } from 'react-native-svg';
import ReactDOMServer from 'react-dom/server';
const isWeb = Platform.OS === 'web';
const childToWeb = child => {
const { type, props } = child;
const name = type && type.displayName;
const webName = name && name[0].toLowerCase() + name.slice(1);
const Tag = webName ? webName : type;
return <Tag {...props}>{toWeb(props.children)}</Tag>;
};
const toWeb = children => React.Children.map(children, childToWeb);
export default class App extends React.Component {
renderSvg() {
return (
<Svg height="100%" width="100%" style={{ backgroundColor: '#33AAFF' }}>
<Rect
x="50"
y="50"
width="50"
height="50"
fill="#3399ff"
strokeWidth="3"
stroke="rgb(0,0,0)"
/>
</Svg>
);
}
serialize = () => {
const element = this.renderSvg();
const webJsx = isWeb ? element : toWeb(element);
const svgString = ReactDOMServer.renderToStaticMarkup(webJsx);
console.log(svgString);
};
render() {
return (
<TouchableOpacity style={styles.container} onPress={this.serialize}>
{this.renderSvg()}
</TouchableOpacity>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
backgroundColor: '#ecf0f1',
padding: 8,
},
});
Run example:
git clone https://github.com/magicismight/react-native-svg-example.git
cd react-native-svg-example
yarn
# run Android: react-native run-android
# run iOS: react-native run-ios
react-native-svg - Fill overlapped area of two ellipses
<svg fill="none" viewBox="140 100 170 170" width="200">
<ellipse cx="192" cy="190" rx="50" ry="80" stroke="red" strokeWidth="2" id="a"/>
<ellipse cx="250" cy="150" rx="60" ry="30" stroke="green" strokeWidth="2" id="b"/>
<use xlink:href="#a" clip-path="url(#cp)" fill="gold"/>
<clipPath id="cp">
<use xlink:href="#b"/>
</clipPath>
<svg>
`useTheme` must be used within `NativeBaseConfigProvider`
import { NativeBaseProvider } from 'native-base';
return (
<NativeBaseProvider>
<View style={styles.container}>
<Header />
<ProductContainer />
</View>
</NativeBaseProvider>
);
Drawer Navigation position right
screenOptions={{drawerPosition:'right',headerShown:false,drawerStyle:{right:0}}}
java.lang.NoSuchMethodError: No virtual method setSkipClientToken(Z)V in class Lcom/facebook/GraphRequest;
implementation 'com.facebook.android:facebook-marketing:[4,5)'
implementation 'com.facebook.android:facebook-marketing:latest.release'
-----------------------
implementation 'com.facebook.android:facebook-marketing:[4,5)'
implementation 'com.facebook.android:facebook-marketing:latest.release'
How to overcome ERESOLVE errors within EAS build for native-base and Expo?
"react-dom": "17.0.1",
"react-native-safe-area-context": "3.1.9",
"react-native-svg": "12.1.0",
Expo SDK 44 upgrade ERROR - App.js: [BABEL]: Unexpected token '.'
expo update 43.0.0
-----------------------
"babel-preset-expo": "9.0.2",
How to create a border radius based off props in react native
<svg width="16" height="16">
<circle r="8" cx="8" cy="8" fill="red" />
<path d="M14.2 0L5.882 8.986 2 4.821 0 6.904 5.682 13 16 1.931 14.2 0z" fill="#fff" />
</svg>
this permision (android.permission.QUERY_ALL_PACKAGES) was automatically added to Manifest
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
tools:node="remove" tools:ignore="QueryAllPackagesPermission" />
eas build -p android fails
com.facebook.yoga:proguard-annotations:1.14.1
com.facebook.fbjni:fbjni-java-only:0.0.3
com.facebook.flipper:flipper:0.54.0
com.facebook.flipper:flipper-network-plugin:0.54.0
com.facebook.flipper:flipper-fresco-plugin:0.54.0
Issue with Auth Flow using react-navigation v6 in React Native. Error: Invalid hook call. Invariant Violation: "main" has not been registered
const LoginScreen = () => {
const { state, dispatch } = React.useContext(AuthContext);
// here you can use a function to login or something, and dispatch it.
return (
<View>
<Text>Login Screen</Text>
</View>
);
};
QUESTION
react-native-svg - Fill overlapped area of two ellipses
Asked 2022-Apr-07 at 17:53We are using react-native-svg library to draw ellipses having following code
<Svg>
<Ellipse cx={192} cy={190} rx={50} ry={80} stroke={"red"} strokeWidth="2"/>
<Ellipse cx={250} cy={150} rx={60} ry={30} stroke={"green"} strokeWidth="2"/>
<Svg>
Which looks like the image below
Our requirement is to fill up the area which gets overlapped by two ellipses.
If anyone can put some light on it, how can it be achieved using the SVG library for react-native? or if anything else we have will be very helpful
Thanks.
ANSWER
Answered 2022-Apr-07 at 17:53The main idea is creating a clipPath with one of the ellipses and reusing the other one clipped by the clipPath.
Please observe that I am giving an id to both ellipses so that I can reuse them with use.
<svg fill="none" viewBox="140 100 170 170" width="200">
<ellipse cx="192" cy="190" rx="50" ry="80" stroke="red" strokeWidth="2" id="a"/>
<ellipse cx="250" cy="150" rx="60" ry="30" stroke="green" strokeWidth="2" id="b"/>
<use xlink:href="#a" clip-path="url(#cp)" fill="gold"/>
<clipPath id="cp">
<use xlink:href="#b"/>
</clipPath>
<svg>
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
Explore Related Topics
Save this library and start creating your kit