Last active
February 26, 2023 18:03
-
-
Save andigu/8356fad72db483e288722a745e8250aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const diffClamp = function( | |
a: Animated.Value<number>, | |
min: number, | |
max: number, | |
): AnimatedDiffClamp { | |
return new AnimatedDiffClamp(a, min, max); | |
}; | |
class AnimatedDiffClamp { | |
constructor(a: Animated.Value<number>, min: number, max: number) { | |
this.a = a; | |
this.emitValue = this.lastInputVal = this.a.__getValue(); | |
this.min = min; | |
this.max = max; | |
} | |
getValue(): number { | |
const currentInputVal = this.a.__getValue(); | |
const diff = currentInputVal - this.lastInputVal; | |
this.lastInputVal = currentInputVal; | |
this.emitValue = Math.min(Math.max(this.emitValue + diff, this.min), this.max); | |
return this.emitValue; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment