React Native SVG

15.15.4 · active · verified Sun Apr 19

React Native SVG is a comprehensive library that brings Scalable Vector Graphics (SVG) support to React Native applications across various platforms, including iOS, Android, macOS, and Windows, with a compatibility layer for the web. The current stable version is 15.15.4. The project maintains an active release cadence, frequently publishing patch and minor versions to address bugs, improve performance, and ensure compatibility with the latest React Native nightly builds and stable releases. A key differentiator is its extensive support for most SVG elements and properties, facilitating the rendering of complex vector graphics directly within native mobile applications. It also simplifies the process of integrating existing SVG assets by supporting conversion tools like SVGR. Furthermore, `react-native-svg` has adapted to React Native's evolving architecture, including early and ongoing support for the Fabric rendering system, though specific versions are required for compatibility.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart renders a basic SVG with a rectangle, circle, text, and line, demonstrating fundamental usage.

import React from 'react';
import { View, StyleSheet } from 'react-native';
import { Svg, Rect, Circle, Line, Text } from 'react-native-svg';

const MySVGComponent = () => {
  return (
    <View style={styles.container}>
      <Svg height="200" width="200" viewBox="0 0 100 100">
        {/* Simple Red Rectangle */}
        <Rect
          x="10"
          y="10"
          width="80"
          height="30"
          stroke="red"
          strokeWidth="2"
          fill="rgba(255,0,0,0.5)"
        />

        {/* Blue Circle */}
        <Circle cx="50" cy="70" r="25" fill="blue" stroke="none" />

        {/* Text */}
        <Text
          x="50"
          y="50"
          textAnchor="middle"
          fill="white"
          fontSize="10"
        >
          Hello SVG!
        </Text>

        {/* Line */}
        <Line
          x1="0"
          y1="0"
          x2="100"
          y2="100"
          stroke="purple"
          strokeWidth="1"
        />
      </Svg>
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
});

export default MySVGComponent;

view raw JSON →