I have an SVG that I've created in react native, and I'd simply like to rotate this 360 degrees continuously in the most efficient way possible.
Thanks.
add in style transform: [{ rotate: '14deg' }], if you make view position absolute it will not affect another view! the rotate start from 0 to 360 deg .
Open up the project in your favorite editor and start by importing the Svg and Circle components from react-native-svg, as shown below. import Svg, { Circle } from 'react-native-svg'; The <Svg> component is a parent component that is needed to render any SVG shape.
Transforms are style properties that will help you modify the appearance and position of your components using 2D or 3D transformations. However, once you apply transforms, the layouts remain the same around the transformed component hence it might overlap with the nearby components.
Just use transform. It works perfectly.
<YourSvg
height={20}
width={20}
style={{ transform: [{ rotateY: '180deg' }] }}
/>
Just wrap your SVG in a View component and make use of the Animated API. Your code would be something in the lines of this:
class YourComponent extends React.Component {
constructor(props) {
super(props);
this.animation = new Animated.Value(0);
}
render() {
const rotation = this.animation.interpolate({
inputRange: [0, 1],
outputRange: ['0deg', '360deg']
});
return (
<Animated.View
style={{transform: [{rotate: rotation}] }}
>
<YourSVG />
</Animated.View>
);
componentDidMount() {
Animated.loop(
Animated.timing(this.animation, {toValue: 1, duration: 2000})
).start();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With