小编art*_*pse的帖子

如何获取AnimatedInterpolation的值

我的问题是如何在react-native中检索AnimatedInterpolation的值,而不调用私有代码。

我创建动画值并将其包装在插值中,如下所示:

  animated = new Animated.Value();
  interpolated = this.animated.interpolate({
    inputRange:[0, 1000],
    outputRange:[0, 500]
  })
Run Code Online (Sandbox Code Playgroud)

我这样渲染动画:

  <Animated.View style={[{width: this.interpolated}]}/>
Run Code Online (Sandbox Code Playgroud)

我像这样检索动画值:

  this.animated.stopAnimation(v => {
    console.log(v, " ", this.interpolated.__getValue());
  })
Run Code Online (Sandbox Code Playgroud)

可运行的例子在这里

我的问题是,它__getValue()是 AnimatedInterpolation 的私有成员,在使用打字稿时会出错。我正在寻找一种合理的方法来检索该值,类似于如何this.animated.stopAnimation比 更合理this.animated.__getValue()

javascript typescript react-native

11
推荐指数
1
解决办法
3463
查看次数

标签 统计

javascript ×1

react-native ×1

typescript ×1