给react native 添加transform translateY动画报错:Transform with key of "translateY" must be a number:{translateY“:0}

发布时间 2023-10-25 13:32:46作者: 九零菜菜

初学react native,想实现一个相机扫描功能时,报错,报错描述如标题

image

这是我的主要逻辑代码

  const fadeAnim = useRef(new Animated.Value(0)).current;

  const move = () => {
    fadeAnim.setValue(0);
    Animated.timing(fadeAnim, {
      toValue: 200,
      duration: 2000,
      easing: Easing.linear ,
      useNativeDriver: true,
    }).start(() => {
      move();
    });
  };

  useEffect(() => {
    move();
  }, []);

这是使用动画的代码

<View
   style={[
       styles.line,
         {
           transform: [
             {
               translateY: fadeAnim,
             },
           ],
         },
]}></View>

可以说这问题很简单,但是我还是犯了,rn可以直接使用动画的组件是 Animated.View,Animated.Text, Animated.Image, Animated.ScrollView所以我用错组件了。。。