获取 Animated.Value 的当前值,React-native [英] Get current value of Animated.Value, React-native

查看:37
本文介绍了获取 Animated.Value 的当前值,React-native的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用插值为 View 设置动画.我想获得我的 Animated.Value 的当前值,但不知道如何.我不明白如何使用 React 原生文档.

I'm trying to animate View with interpolate. I'd like to get a current value of my Animated.Value, but don't know how. I didn't understand how to do it with 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
}

推荐答案

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

I find out, how to get a value:

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

编辑

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

to log a value I do the following:

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

这篇关于获取 Animated.Value 的当前值,React-native的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆