Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native Animated singleValue.stopTracking is not a function

Tags:

react-native

I have the following code to animate in React Native

Animated.timing(     this.state.absoluteChangeX,     {toValue: 0}, ).start(function() {     this.lastX = 0;     this.lastY = 0; });  

Pretty simple, but whenever it's triggered, I receive the error: singleValue.stopTracking is not a function

Here's where the error originates:

/react-native/Libraries/Animates/src/AnimtaedImplementation.js

var timing = function(   value: AnimatedValue | AnimatedValueXY,   config: TimingAnimationConfig, ): CompositeAnimation {   return maybeVectorAnim(value, config, timing) || {     start: function(callback?: ?EndCallback): void {       var singleValue: any = value;       var singleConfig: any = config;       singleValue.stopTracking(); // <--------------- HERE!!!       if (config.toValue instanceof Animated) {         singleValue.track(new AnimatedTracking(           singleValue,           config.toValue,           TimingAnimation,           singleConfig,           callback         ));       } else {         singleValue.animate(new TimingAnimation(singleConfig), callback);       }     },      stop: function(): void {       value.stopAnimation();     },   }; }; 

I'm not extremely versed in typeScript, but var singleValue: any means that "singleValue" could be any type. In my case, it's a number. Since numbers don't have methods, it would make sense that this would error.

Am I doing something wrong?

like image 478
jaxoncreed Avatar asked Mar 13 '16 16:03

jaxoncreed


People also ask

How do I change Animated value React Native?

setValue() ​ setValue(value); Directly set the value. This will stop any animations running on the value and update all the bound properties.

How do I stop Animated timings in React Native?

If an animation is in process of being animated and, for any particular reason, you need to stop it, you can call stopAnimation . The stopAnimation call also takes a callback with the value that the animation was stopped on. this. _animatedValue = new Animated.


1 Answers

The value you wish to animate must be an instance of Animated.Value, or one of its subtypes. When you initialize your state, it should look something like this:

getInitialState() {   return { absoluteChangeX: new Animated.Value(0) }; } 

The fact that the type declaration in the framework method is any is just a lack of constraint, not an explicit invitation to pass any value into it.

See the Animated docs for more examples.

like image 82
jevakallio Avatar answered Sep 17 '22 21:09

jevakallio