【问题标题】:React Native/Typescript/Eslint error: Type 'void' is not assignable to type 'CompositeAnimation'React Native/Typescript/Eslint 错误:类型“void”不可分配给类型“CompositeAnimation”
【发布时间】:2019-04-14 01:29:30
【问题描述】:

我是打字稿的新手。 linter 已经能够为我快速修复,但以下代码部分没有提供可用于 linter 修复的快速操作:

问题消息是“类型'void'不可分配给类型'CompositeAnimation'.ts(2322)”

Animated.parallel([
     Animated.spring(this.position, {
         toValue: ({ x: 0, y: 0 }),
     }).start(),
     Animated.spring(this.swipeCardPosition, {
         toValue: ({ x: 0, y: -SCREEN_HEIGHT }),
     }).start(),
]).start();

【问题讨论】:

    标签: typescript react-native animation


    【解决方案1】:

    我认为问题在于 Animated.parallel() 方法接受复合动画对象的数组。 Animate.spring() 返回一个复合动画对象,但是您对这两个动画都调用了 start() 方法,它的返回类型为 void。

    试试下面的代码,我认为它应该可以工作:

    Animated.parallel([
     Animated.spring(this.position, {
         toValue: ({ x: 0, y: 0 }),
     }),
     Animated.spring(this.swipeCardPosition, {
         toValue: ({ x: 0, y: -SCREEN_HEIGHT }),
     }),
    ]).start();
    

    请注意,我没有启动弹簧动画,我只是启动包含两个弹簧动画的“根”动画。

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 2016-06-24
      • 2020-07-29
      • 2019-06-07
      • 2020-07-22
      • 2020-11-09
      • 2020-07-24
      • 2022-08-23
      • 2021-02-06
      • 2021-04-18
      相关资源
      最近更新 更多