Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get current value of Animated.Value, React-native

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 } 
like image 219
Evgeny Kuznetsov Avatar asked Jan 30 '17 09:01

Evgeny Kuznetsov


People also ask

How do I get the value of Animated React Native?

To get the current value of Animated. Value with React Native, we call addListener on the animated value object. to call spinValue. addListener with a callback to get the current value of the animated value from the value property.

What is Animated value?

Standard value for driving animations. One Animated. Value can drive multiple properties in a synchronized fashion, but can only be driven by one mechanism at a time. Using a new mechanism (e.g. starting a new animation, or calling setValue ) will stop any previous ones.

How do you reset Animated value React Native?

You can use this. spinValue. setValue(0) to reset it. You can add it at the beginning of handlePress .


2 Answers

I find out, how to get a value:

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

EDIT

to log a value I do the following:

console.log(this.state.translateAnim._value) 
like image 111
Evgeny Kuznetsov Avatar answered Oct 10 '22 17:10

Evgeny Kuznetsov


This also works for me...

const headerHeight = new Animated.Value(0); 

After some manipulation....

console.log(headerHeight.__getValue()) 

It feels hackish but it gets the job done...

like image 41
moQuez Avatar answered Oct 10 '22 17:10

moQuez