Skip to content

Instantly share code, notes, and snippets.

@piaskowyk
Created November 12, 2020 11:53
Show Gist options
  • Save piaskowyk/d87e4d3486c4060392730f960f14f222 to your computer and use it in GitHub Desktop.
Save piaskowyk/d87e4d3486c4060392730f960f14f222 to your computer and use it in GitHub Desktop.
import React, {Component} from 'react';
import {View, TouchableOpacity, Text} from 'react-native';
import Animated, {
useSharedValue,
useAnimatedStyle,
withTiming,
} from 'react-native-reanimated';
function RotationAnimation(props) {
var rotationValue = 0;
var rotation = useSharedValue(rotationValue);
var animatedStyle = useAnimatedStyle(() => {
return {
transform: [{rotateZ: `${rotation.value}deg`}],
};
});
const rotateClockwise = rv => {
var newRotationValue = parseInt(rv) * 1 + 90;
rotation.value = withTiming(newRotationValue, {duration: 100});
rotationValue = newRotationValue;
};
return (
<TouchableOpacity onPress={() => rotateClockwise(rotationValue)}>
<Animated.View
style={[
{
height: 100,
width: 100,
backgroundColor: 'purple',
borderColor: '#fff',
borderWidth: 1,
},
animatedStyle,
]}>
<Text
style={{
color: '#fff',
}}>
Code
</Text>
</Animated.View>
</TouchableOpacity>
);
}
export default class Index extends Component {
constructor(props) {
super(props);
}
renderView() {
var count = 6;
return [...Array(count)].map((options, key) => {
return <RotationAnimation key={key} />;
});
}
render() {
return (
<View>
<View style={{flexDirection: 'row', flexWrap: 'wrap'}}>
{this.renderView()}
</View>
</View>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment