React Native 重新启动不适用于插值

Joh*_*Doe 3 reactjs react-native react-native-reanimated

我尝试使用 Animated.interpolate 但出现了一个我从未遇到过的奇怪错误。怎么解决呢?谢谢

- 在此输入图像描述

Mat*_*nho 7

使用 interpolate 的变量应该位于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,
    };
  });
Run Code Online (Sandbox Code Playgroud)