Skip to content

Instantly share code, notes, and snippets.

@vikas-0

vikas-0/index.js Secret

Created February 6, 2022 07:47
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 vikas-0/24c785c2a178a790b3b7352b400cc400 to your computer and use it in GitHub Desktop.
Save vikas-0/24c785c2a178a790b3b7352b400cc400 to your computer and use it in GitHub Desktop.
SVG animation example using react native reanimted
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