Created
November 12, 2020 11:53
-
-
Save piaskowyk/d87e4d3486c4060392730f960f14f222 to your computer and use it in GitHub Desktop.
This file contains hidden or 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, {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