获取Animated.Value,React-native的当前值

问题描述 投票:33回答:3

我正在尝试使用插值动画查看。我想得到我的Animated.Value的当前值,但不知道如何。我不明白如何用React-native docs做到这一点。

this.state = {
      translateAnim: new Animated.Value(0)
}
DeviceEventEmitter.addListener('Accelerometer', function (data) {
  console.log(this.state.translateAnim);
  // returns an object, but I need a value in current moment
}
reactjs react-native react-native-android
3个回答
52
投票

我发现,如何获得一个值:

this.state.translateAnim.addListener(({value}) => this._value = value);

编辑

要记录一个值,我会执行以下操作:

console.log(this.state.translateAnim._value)

10
投票

我没有声明添加评论,但对于有打字稿的人。

console.log((this.state.translateAnim as any)._value);

对我来说,它对任何人来说都是完整的。


8
投票

这对我也有用......

const headerHeight = new Animated.Value(0);

经过一些操纵......

console.log(headerHeight.__getValue())

它感觉很乱,但它完成了工作......

© www.soinside.com 2019 - 2024. All rights reserved.