### Start Example App (iOS)
Source: https://github.com/software-mansion/react-native-svg/blob/main/CONTRIBUTING.md
Launches the example application on an iOS simulator or device. Ensure the Metro server is running.
```bash
yarn ios
```
--------------------------------
### Start Example App (Android)
Source: https://github.com/software-mansion/react-native-svg/blob/main/CONTRIBUTING.md
Launches the example application on an Android device or emulator. Ensure the Metro server is running.
```bash
yarn android
```
--------------------------------
### Line Example
Source: https://github.com/software-mansion/react-native-svg/blob/main/_autodocs/api-reference/shape-elements.md
Render a straight line with start and end coordinates, stroke color, and stroke width.
```jsx
import { Line } from 'react-native-svg';
```
--------------------------------
### Complete SVG Configuration Example
Source: https://github.com/software-mansion/react-native-svg/blob/main/_autodocs/configuration.md
A comprehensive example demonstrating the setup of a React Native SVG component, including rendering size, default styling, transforms, accessibility, touch handling, and nested elements with gradients.
```jsx
import React from 'react';
import { Svg, Rect, Circle, Defs, LinearGradient, Stop } from 'react-native-svg';
export const ConfiguredSvg = () => (
);
```
--------------------------------
### Using FillRule Example
Source: https://github.com/software-mansion/react-native-svg/blob/main/_autodocs/types.md
Example of setting the fillRule attribute for a Path component, using 'evenodd' to determine how the inside of a shape is determined.
```jsx
```
--------------------------------
### Using Transform Example
Source: https://github.com/software-mansion/react-native-svg/blob/main/_autodocs/types.md
Example of applying a 2D transformation to a G (group) element using an array representing the transformation matrix.
```jsx
```
--------------------------------
### Basic SVG with Shapes Example
Source: https://github.com/software-mansion/react-native-svg/blob/main/_autodocs/api-reference/svg-root.md
A basic example demonstrating how to create an SVG element and render shapes like Rect, Circle, and Line within it.
```jsx
import React from 'react';
import { View } from 'react-native';
import Svg, { Circle, Rect, Line } from 'react-native-svg';
export const BasicSvg = () => (
);
```
--------------------------------
### Line Element Example
Source: https://github.com/software-mansion/react-native-svg/blob/main/USAGE.md
Shows how to draw a line connecting two points using the Line element. Properties x1, y1, x2, y2 define the start and end points, while stroke and strokeWidth style the line.
```jsx
```
--------------------------------
### Rect Examples
Source: https://github.com/software-mansion/react-native-svg/blob/main/_autodocs/api-reference/shape-elements.md
Render a basic rectangle with position, dimensions, and fill, or a rectangle with rounded corners.
```jsx
import { Rect } from 'react-native-svg';
// Basic rectangle
// Rectangle with rounded corners
```
--------------------------------
### Install react-native-svg with yarn
Source: https://github.com/software-mansion/react-native-svg/blob/main/README.md
Install the react-native-svg library using yarn. This command is used for projects managed with yarn.
```bash
yarn add react-native-svg
```
--------------------------------
### Responsive SVG with ViewBox Example
Source: https://github.com/software-mansion/react-native-svg/blob/main/_autodocs/api-reference/svg-root.md
Demonstrates creating a responsive SVG that adjusts its size based on the window dimensions and uses viewBox and preserveAspectRatio for scaling.
```jsx
import React from 'react';
import { Dimensions } from 'react-native';
import Svg, { Circle } from 'react-native-svg';
export const ResponsiveSvg = () => {
const { width } = Dimensions.get('window');
const size = Math.min(width, 300);
return (
);
};
```
--------------------------------
### Circle Example
Source: https://github.com/software-mansion/react-native-svg/blob/main/_autodocs/api-reference/shape-elements.md
Render a basic circle with specified center coordinates, radius, fill, stroke, and stroke width.
```jsx
import { Circle } from 'react-native-svg';
```
--------------------------------
### Rendering Multiple Markers on a Path
Source: https://github.com/software-mansion/react-native-svg/blob/main/USAGE.md
This example demonstrates applying different markers (start, mid, and end) to a single path element. It uses SvgXml to render an SVG string containing multiple marker definitions and a path utilizing them.
```jsx
import React from 'react';
import { StyleSheet, View } from 'react-native';
import { SvgXml } from 'react-native-svg';
const markerRendering = ``;
export default class App extends React.Component {
render() {
return (
);
}
}
const styles = StyleSheet.create({
container: {
backgroundColor: 'white',
justifyContent: 'center',
alignItems: 'center',
flex: 1,
},
});
```
--------------------------------
### Polyline Examples
Source: https://github.com/software-mansion/react-native-svg/blob/main/_autodocs/api-reference/shape-elements.md
Render an open polyline using points defined as a string or an array, with stroke and fill properties.
```jsx
import { Polyline } from 'react-native-svg';
// As string
// As array
```
--------------------------------
### Install react-native-svg with npm
Source: https://github.com/software-mansion/react-native-svg/blob/main/README.md
Install the react-native-svg library using npm. This is a common step for projects managed with npm.
```bash
npm install react-native-svg
```
--------------------------------
### FeMerge Example
Source: https://github.com/software-mansion/react-native-svg/blob/main/_autodocs/api-reference/filter-elements.md
Combines multiple filter primitive results into a single output. This example applies a blur and then merges it with the original graphic.
```jsx
```
--------------------------------
### Complete Filter Example with Drop Shadow
Source: https://github.com/software-mansion/react-native-svg/blob/main/_autodocs/api-reference/filter-elements.md
This example demonstrates how to define and apply a drop shadow filter to multiple shapes within an SVG. It includes setting up the filter in Defs and applying it using the filter prop.
```jsx
import React from 'react';
import { Svg, Defs, Filter, FeGaussianBlur, FeMerge, FeOffset,
FeMergeNode, Rect, Circle } from 'react-native-svg';
export const FilterExample = () => (
);
```
--------------------------------
### Using FontWeight Example
Source: https://github.com/software-mansion/react-native-svg/blob/main/_autodocs/types.md
Demonstrates setting the fontWeight property for a Text component using either a keyword like 'bold' or a numeric string like '600'.
```jsx
```
--------------------------------
### Link native code for iOS
Source: https://github.com/software-mansion/react-native-svg/blob/main/README.md
After installing the library, run this command in the 'ios' directory to link the native code for iOS projects.
```bash
cd ios && pod install
```
--------------------------------
### FeBlend Element Example
Source: https://github.com/software-mansion/react-native-svg/blob/main/_autodocs/api-reference/filter-elements.md
Shows how to use FeBlend to combine two inputs with a specified blend mode. The 'mode' prop determines the blending operation.
```jsx
```
--------------------------------
### FeTurbulence Example
Source: https://github.com/software-mansion/react-native-svg/blob/main/_autodocs/api-reference/filter-elements.md
Generates a fractal noise texture. This example creates a marble-like effect using fractal noise with specified frequency and octaves.
```jsx
```
--------------------------------
### Using NumberProp Example
Source: https://github.com/software-mansion/react-native-svg/blob/main/_autodocs/types.md
Example of using NumberProp for numeric or percentage-based values in SVG attributes like cx, cy, and r.
```jsx
```
--------------------------------
### SVG Export to Data URL Example
Source: https://github.com/software-mansion/react-native-svg/blob/main/_autodocs/api-reference/svg-root.md
An example showing how to export an SVG to a base64 data URL using the `toDataURL` method and a ref. This is useful for saving or sharing the SVG.
```jsx
import React, { useRef } from 'react';
import { TouchableOpacity, Text } from 'react-native';
import Svg, { Path } from 'react-native-svg';
export const ExportableSvg = () => {
const svgRef = useRef(null);
const exportImage = () => {
svgRef.current?.toDataURL((base64) => {
// Use base64 string to save file, share, etc.
console.log(base64);
});
};
return (
Tap to Export
);
};
```
--------------------------------
### Run E2E Tests
Source: https://github.com/software-mansion/react-native-svg/blob/main/CONTRIBUTING.md
Executes the end-to-end tests for the project. Ensure you have followed the setup instructions for E2E testing.
```bash
yarn e2e
```
--------------------------------
### Rect Element Example
Source: https://github.com/software-mansion/react-native-svg/blob/main/USAGE.md
Shows how to create a rectangle using the Rect element. Properties like x, y, width, height, fill, strokeWidth, and stroke are demonstrated.
```jsx
```
--------------------------------
### Svg toDataURL Method Usage Example
Source: https://github.com/software-mansion/react-native-svg/blob/main/_autodocs/api-reference/svg-root.md
Example of using the `toDataURL` method on an SVG component's ref to get its base64 representation. This is typically used within a component that handles exporting or saving the SVG.
```jsx
const svgRef = useRef(null);
const handleExport = () => {
svgRef.current?.toDataURL((base64) => {
console.log('SVG as data URL:', base64);
});
};
return (
<>
Export
>
);
```
--------------------------------
### FeComponentTransfer Example
Source: https://github.com/software-mansion/react-native-svg/blob/main/_autodocs/api-reference/filter-elements.md
Remaps color components (Red, Green, Blue, Alpha) using transfer functions. This example increases brightness by scaling RGB channels.
```jsx
```
--------------------------------
### Polygon Element Example
Source: https://github.com/software-mansion/react-native-svg/blob/main/USAGE.md
Demonstrates creating a polygon with at least three sides using the Polygon element. The 'points' prop defines the coordinates of each corner.
```jsx
```
--------------------------------
### Install react-native-svg with Expo
Source: https://github.com/software-mansion/react-native-svg/blob/main/README.md
Use this command to install react-native-svg when working with Expo. The Expo client app includes the necessary native code.
```bash
npx expo install react-native-svg
```
--------------------------------
### Using NumberArray Example
Source: https://github.com/software-mansion/react-native-svg/blob/main/_autodocs/types.md
Example of using NumberArray for attributes like x and y in the Text component, accepting an array of numbers or a percentage string.
```jsx
A B C
```
--------------------------------
### FeOffset Example
Source: https://github.com/software-mansion/react-native-svg/blob/main/_autodocs/api-reference/filter-elements.md
Applies a horizontal and vertical offset to an input graphic, commonly used for creating drop shadows.
```jsx
```
--------------------------------
### Circle Element Example
Source: https://github.com/software-mansion/react-native-svg/blob/main/USAGE.md
Demonstrates the creation of a circle using the Circle element. Key properties include cx, cy for the center coordinates, r for the radius, and fill for the color.
```jsx
```
--------------------------------
### Polygon Examples
Source: https://github.com/software-mansion/react-native-svg/blob/main/_autodocs/api-reference/shape-elements.md
Render a closed polygon using points defined as a string or an array, with fill and stroke properties.
```jsx
import { Polygon } from 'react-native-svg';
// As string
// As array
```
--------------------------------
### Ellipse Example
Source: https://github.com/software-mansion/react-native-svg/blob/main/_autodocs/api-reference/shape-elements.md
Render an ellipse with specified center coordinates, horizontal and vertical radii, and fill color.
```jsx
import { Ellipse } from 'react-native-svg';
```
--------------------------------
### Svg Component with ViewBox Examples
Source: https://github.com/software-mansion/react-native-svg/blob/main/_autodocs/configuration.md
Demonstrates different configurations for the viewBox attribute to define the SVG coordinate system. Use these to set the origin and scale of your SVG content.
```jsx
// Standard square (origin at 0,0, 100x100 units)