Skip to content

Instantly share code, notes, and snippets.

@n-ii-ma
Created January 6, 2024 07:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n-ii-ma/85bf643b42574b9a924f82e4addb56e7 to your computer and use it in GitHub Desktop.
Save n-ii-ma/85bf643b42574b9a924f82e4addb56e7 to your computer and use it in GitHub Desktop.
Responsive SVG in React Native
import { View } from "react-native";
import { memo } from "react";
import Svg, { Circle, Path } from 'react-native-svg';
// Calculate aspect ratio
const originalWidth = 500;
const originalHeight = 500;
const aspectRatio = originalWidth / originalHeight;
const SVG = () => (
<View style={{ width: "100%", aspectRatio }}>
<Svg width="100%" height="100%" viewBox={`0 0 ${originalWidth} ${originalHeight}`}>
<Circle cx="250" cy="250" r="40" fill="yellow" />
<Circle cx="240" cy="240" r="4" fill="black" />
<Circle cx="260" cy="240" r="4" fill="black" />
<Path d="M 240 265 A 20 20 0 0 0 260 260" strokeWidth={2} stroke="black" />
</Svg>
</View>
);
export default memo(SVG);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment