Skip to content

Instantly share code, notes, and snippets.

@ozcanzaferayan
Last active May 2, 2020 23:22
Show Gist options
  • Select an option

  • Save ozcanzaferayan/b774fd48ca27ce782c265e8697bec01c to your computer and use it in GitHub Desktop.

Select an option

Save ozcanzaferayan/b774fd48ca27ce782c265e8697bec01c to your computer and use it in GitHub Desktop.
Rotate animation for weird piechart
/* eslint-disable react-native/no-inline-styles */
import React from 'react';
import {
SafeAreaView,
StyleSheet,
StatusBar,
Animated,
Easing,
} from 'react-native';
import Svg, {Circle} from 'react-native-svg';
const App = () => {
const viewBoxWidth = 42;
const viewBoxHeight = 140;
const viewBox = `0 0 ${viewBoxWidth} ${viewBoxHeight}`;
const centerX = viewBoxWidth / 2;
const centerY = viewBoxHeight / 2;
const colorPrimary = '#dd0000';
const spinValue = new Animated.Value(0);
Animated.loop(
Animated.timing(spinValue, {
toValue: 1,
duration: 3000,
easing: Easing.linear,
useNativeDriver: true,
}),
).start();
const spin = spinValue.interpolate({
inputRange: [0, 1],
outputRange: ['0deg', '360deg'],
});
return (
<>
<StatusBar barStyle="dark-content" />
<Animated.View
style={{...styles.safeAreaView, transform: [{rotate: spin}]}}>
<Svg viewBox={viewBox} style={{transform: [{rotateZ: '-90deg'}]}}>
<Circle
cx={centerX}
cy={centerY}
r={10}
stroke={colorPrimary}
fill={colorPrimary}
strokeWidth={viewBoxWidth}
strokeDasharray={3}
strokeDashoffset={10}
/>
</Svg>
</Animated.View>
</>
);
};
const styles = StyleSheet.create({
safeAreaView: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
padding: 24,
},
});
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment