Created
January 6, 2024 07:17
-
-
Save n-ii-ma/85bf643b42574b9a924f82e4addb56e7 to your computer and use it in GitHub Desktop.
Responsive SVG in React Native
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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