react-native-svg
@amazon-devices/react-native-svg
provides SVG support to React Native on Vega and a compatibility layer for the web.
@amazon-devices/react-native-svg
supports most SVG elements and properties, such as Rect, Circle, Line, Polyline, Polygon, and G. This library allows simple conversion of SVG code to react-native-svg
component.
This is a system-deployed library and is available to React Native for Vega apps without a separate installation process. It is deployed as an autolinking library which your app links to at runtime. Compatibility is guaranteed only between the library and the version of React Native for Vega for which it is built.
When you upgrade the version of React Native for Vega upon which your app is built, it is best practice to also upgrade the versions of the libraries that depend on React Native for Vega.
Installation
- Add the JavaScript library dependency in the
package.json
file."dependencies": { ... "@amazon-devices/react-native-svg": "~2.0.0" }
- Reinstall dependencies using
npm install
command.
Examples
The example below demonstrates how to render a Circle
component.
import { Circle, Svg } from '@amazon-devices/react-native-svg';
import React from 'react';
import { StyleSheet, View } from 'react-native';
const CircleExample = () => {
return (
<Svg height="100" width="100">
<Circle cx="50%" cy="50%" r="40%" fill="pink" />
</Svg>
);
};
const App = () => {
return (
<View style={styles.container}>
<CircleExample />
</View>
);
};
const styles = StyleSheet.create({
container: {
backgroundColor: 'white',
flex: 1,
},
});
export default App;
The example below demonstrates how to render a Polygon
component.
import { G, Polygon, Svg } from '@amazon-devices/react-native-svg';
import React from 'react';
import { StyleSheet, View } from 'react-native';
const StarExample = () => {
return (
<Svg height="105" width="105">
<G scale="0.5">
<Polygon
points="100,10 40,198 190,78 10,78 160,198"
fill="lime"
stroke="purple"
strokeWidth="5"
/>
</G>
</Svg>
);
};
const App = () => {
return (
<View style={styles.container}>
<StarExample />
</View>
);
};
const styles = StyleSheet.create({
container: {
backgroundColor: 'white',
flex: 1,
},
});
export default App;
API reference
Check out dedicated documentation page for info about this library, API reference and more on GitHub.
The SVG library on Vega adds support for the SVG components and touch events listed, as listed below.
Components
Component | Description |
---|---|
Svg |
HOC for other elements |
Rect |
The element is used to create a rectangle and variations of a rectangle shape |
Circle |
The element is used to create a circle |
Ellipse |
The element is used to create an ellipse. An ellipse is closely related to a circle. The difference is that an ellipse has an x and a y radius that differs from each other, while a circle has equal x and y radius |
Line |
The element is an SVG basic shape, used to create a line connecting two points |
Path |
The element is used to define a path |
Text |
The element is used to define text |
TSpan |
The element is used to draw multiple lines of text in SVG. Rather than having to position each line of text absolutely, the element makes it possible to position a line of text relatively to the previous line of text |
G |
The element is a container used to group other SVG elements |
Image |
The element allows a raster image to be included in an Svg component |
ClipPath |
The SVG element defines a clipping path. A clipping path is used/referenced using the clipPath property |
Use |
The element can reuse an SVG shape from elsewhere in the SVG document |
Defs |
The element is used to embed definitions that can be reused inside an SVG image |
RadialGradient |
The element is used to define a radial gradient. The element must be nested within a <Defs> tag |
LinearGradient |
The element is used to define a linear gradient. The element must be nested within a <Defs> or <Svg> tag |
Mask |
In SVG, you can specify that any other graphics object or G element can be used as an alpha mask for compositing the current object into the background |
Touch events
Event |
---|
disabled |
onPress |
onPressIn |
onPressOut |
onLongPress |
delayPressIn |
delayPressOut |
delayLongPress |
Exceptions on Vega
Unsupported APIs
The APIs listed below are not supported on Vega at this time.
- The following SVG components are not functional:
- Markers
- TouchEvents
Pattern
andpatternTransform
are not yet supported
Unsupported components
The SVG components listed in the table below are not supported on Vega at this time.
Component | Description |
---|---|
Polygon |
The element is used to create a graphic that contains at least three sides. Polygons are made of straight lines, and the shape is "closed" (all the lines connect up) |
Polyline |
The element is used to create any shape that consists of only straight lines |
TextPath |
In addition to text drawn in a straight line, SVG also includes the ability to place text along the shape of an element. To specify that a block of text is to be rendered along the shape of an element, include the given text within an element that includes an href attribute with a reference to the element |
Symbol |
The SVG element is used to define reusable symbols |
Pattern |
A pattern is used to fill or stroke an object using a pre-defined graphic object which can be replicated ("tiled") at fixed intervals in x and y to cover the areas to be painted |
Marker |
A marker is a symbol which is attached to one or more vertices of ‘path’, ‘line’, ‘polyline’ and ‘polygon’ elements. Typically, markers are used to make arrowheads or polymarkers |
ForeignObject |
Allows for inclusion of elements in a non-SVG namespace which is rendered within a region of the SVG graphic using other user agent processes |
Supported versions
Package name | Amazon NPM library version | Vega OS build number | Vega SDK version | Release notes |
---|---|---|---|---|
@amazon-devices/react-native-svg |
2.1.0+13.14.0 | OS 1.1 (201010438050) |
0.20 |
Additional resources
For information on additonal libraries, see Supported Third-Party Libraries and Services.
Last updated: Sep 30, 2025