-
-
Save vikas-0/24c785c2a178a790b3b7352b400cc400 to your computer and use it in GitHub Desktop.
SVG animation example using react native reanimted
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 React from 'react'; | |
import { View } from 'react-native-animatable'; | |
import { Button } from 'react-native-paper'; | |
import Animated, { useSharedValue, useAnimatedProps, withSpring } from 'react-native-reanimated'; | |
import Svg, { Circle } from 'react-native-svg'; | |
const AnimatedCircle = Animated.createAnimatedComponent(Circle); | |
export default () => { | |
const radius = useSharedValue(50); | |
const strokeWidth = 5; | |
const animatedProps = useAnimatedProps(() => ({ | |
cx: `${radius.value + strokeWidth}`, | |
cy: `${radius.value + strokeWidth}`, | |
r: `${radius.value}` | |
})); | |
return ( | |
<View | |
style={{ | |
flex: 1, | |
alignItems: 'center', | |
justifyContent: 'center' | |
}} | |
> | |
<View> | |
<Svg width={200} height={200}> | |
<AnimatedCircle animatedProps={animatedProps} stroke="black" strokeWidth={strokeWidth} /> | |
</Svg> | |
</View> | |
<Button | |
mode="contained" | |
onPress={() => { | |
if (radius.value < 80) { | |
radius.value = withSpring(80); | |
} else { | |
radius.value = withSpring(50); | |
} | |
}} | |
> | |
Press | |
</Button> | |
</View> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment