-
Hello, here is my question. i want to write a interpolate that works with greater than logic like this :
How to achieve this ? i already know about my below solution is there something better ?
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Hey! I'm afraid I don't get what you are trying to achieve with this In general,
This range doesn't necessarily have to consist only 2 values (the lower and the upper bound). It can have multiple steps, but the number of steps in the input: will map:
you also can specify the extrapolate parameter (maybe this is what you are looking for). Let me know if it helps or please clarify the question and I will try to help you then. |
Beta Was this translation helpful? Give feedback.
-
@MatiPl01 thanks for the detailed answer. but let me explain more: scrollY.value in my app ranges from 0 to +infinity (maybe 1000 - or maybe 1000000) and i want my output range for this input to behave like this : from 0 to 5 output should be 45 |
Beta Was this translation helpful? Give feedback.
-
Thanks for explanation. You can do a little trick in here based on the knowledge from my previous comment. ExplanationIf you want your interpolated value to be constant when it exceeds your This is the default behavior of the clamp extrapolation: What you are trying to achieve is just a different version of this example with a single-value input range. Something like this: You have 2 possible solution to achieve the desired effect: Solution
const SMALL_DELTA = 1e-6; // 10^-6 = 0.000001
const animatedHeight = interpolate(scrollY.value, [5, 5 + SMALL_DELTA], [45, 0], Extrapolation.CLAMP)
const animatedHeight = interpolate(scrollY.value, [5, 5, 5 /* anything */], [45, 0, 0], Extrapolation.CLAMP) Specifying just 2 equal values in the input range |
Beta Was this translation helpful? Give feedback.
Thanks for explanation. You can do a little trick in here based on the knowledge from my previous comment.
Explanation
If you want your interpolated value to be constant when it exceeds your
input
range (in your case it must be always a constant number but different for different input values), you have to use Extrapolation.CLAMP as the last parameter of theinterpolate
function call.This is the default behavior of the clamp extrapolation:
What you are trying to achieve is just a different version of this example with a single-value input range. Something like this:
You have 2 possible solution to achieve the desired effect:
Solution
input
range where the second value is sligh…