Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare two Animated Interpolations objects together in react native

Tags:

react-native

I need to compare the values of two AnimatedInterpolation objects in react-native. I want to know which AnimatedInterpolation has the smallest decimal value.

Interpolation documentation

Unfortunately, Math.min(value1, value2) doesn't work.

How can I get the float value of an AnimatedInterpolation object ?

I have tried the following :

interpolateOpacity = () => {
    let xOpacity = this.state.pan.x.interpolate({
      inputRange: this.props.inputOpacityRangeX,
      outputRange: this.props.outputOpacityRangeX
    });

    let yOpacity = this.state.pan.y.interpolate({
      inputRange: this.props.inputOpacityRangeY,
      outputRange: this.props.outputOpacityRangeY
    });

    return Math.min(xOpacity, yOpacity) // NOT WORKING
};

Debugger:

Debugger

like image 862
AlexB Avatar asked Dec 08 '25 10:12

AlexB


1 Answers

The way I would do this would be to compare the input values.

If your mapping for the output range isn't significantly complicated, you should be able to compare the input ranges like this by accessing this.state.pan.x._value and this.state.pan.y._value, or better practice would be to set up a listener as described here.

I don't think there is a way to compare the interpolated values in real-time.

like image 77
Jason Gaare Avatar answered Dec 11 '25 01:12

Jason Gaare



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!