Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native reanimated doesn't work with interpolate

I try to use Animated.interpolate but I get a strange error that I've never had. How can it be solved ? Thanks

- enter image description here

like image 819
John Doe Avatar asked Oct 25 '25 11:10

John Doe


1 Answers

The variable that is using interpolate should be inside useAnimatedStyle.

const positionX = useSharedValue(-40);
const animatedStyles = useAnimatedStyle(() => {
    const opacity = interpolate(positionX.value, [-40, 0], [0, 1]); // <- It must be here to work.
    return {
      transform: [{ translateX: positionX.value }],
      opacity,
    };
  });
like image 183
Mateus Marinho Avatar answered Oct 27 '25 00:10

Mateus Marinho



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!