3

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)?

BSMP
  • 4,596
  • 8
  • 33
  • 44
viki
  • 57
  • 1
  • 2
  • i m used Math.PI but its not getting proper result – viki Jul 13 '20 at 07:36
  • Can you update your question to include a [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). Currently it is not possible to run your code (as you haven't included any), so the ability for anyone to provide meaningful help is limited. – Andrew Jul 13 '20 at 07:43

4 Answers4

7

Probably you need concat function from reanimated library:

import Animated, { concat } from 'react-native-reanimated';
...
return (
  <Animated.View style={{
    transform: [{rotateZ: concat(yourAnimatedValue, 'deg')}],
  }}/>
);
Aliaksei
  • 1,094
  • 11
  • 20
4

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` }],
    }
  })
lmasneri
  • 589
  • 7
  • 17
1

dont forget to pass as string like { transform: [{ rotate: '45deg' }] } not rotate: 45deg

Amir Doreh
  • 1,369
  • 1
  • 13
  • 25
0

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",
            },
          ],
        };
      });
Ahmed5G
  • 310
  • 2
  • 8