Reputation: 77
I'm learning reanimated because it works on the UI thread and I want to achieve a rotation animation. Rotating in degrees (like 45deg) is not working and prompts an error. So how can we achieve rotation animation in react-native-reanimation v1(version 1)?
Upvotes: 4
Views: 9516
Reputation: 385
this way worked with me
"react-native-reanimated": "~2.12.0",
let openTabProgress = useSharedValue(0);
//careful next line it is useDerivedValue not useSharedValue
let iconRotate = useDerivedValue(() => {
return interpolate(openTabProgress.value, [0, 1], [0, 180]);
});
const upIconReanimatedStyle = useAnimatedStyle(() => {
return {
transform: [
{
rotate: iconRotate.value + "deg",
},
],
};
});
Upvotes: 2
Reputation: 761
The easiest way for me is doing like this (even if I don't understand why there is no interpolate for input number[]
to output string[]
...
const animatedStyle = useAnimatedStyle(() => {
return {
transform: [{ rotate: `${interpolate(rotation.value, [0, 1], [90, 180])}deg` }],
}
})
Upvotes: 6
Reputation: 1261
Probably you need concat
function from reanimated library:
import Animated, { concat } from 'react-native-reanimated';
...
return (
<Animated.View style={{
transform: [{rotateZ: concat(yourAnimatedValue, 'deg')}],
}}/>
);
Upvotes: 8
Reputation: 1429
dont forget to pass as string like { transform: [{ rotate: '45deg' }] }
not rotate: 45deg
Upvotes: 1