diff --git a/Libraries/Animated/src/AnimatedImplementation.js b/Libraries/Animated/src/AnimatedImplementation.js index 830ab929d..4c7a85a4d 100644 --- a/Libraries/Animated/src/AnimatedImplementation.js +++ b/Libraries/Animated/src/AnimatedImplementation.js @@ -898,6 +898,33 @@ class AnimatedMultiplication extends AnimatedWithChildren { } } +class AnimatedModulo extends AnimatedWithChildren { + _a: Animated; + _modulus: number; + + constructor(a: Animated, modulus: number) { + super(); + this._a = a; + this._modulus = modulus; + } + + __getValue(): number { + return (this._a.__getValue() % this._modulus + this._modulus) % this._modulus; + } + + interpolate(config: InterpolationConfigType): AnimatedInterpolation { + return new AnimatedInterpolation(this, Interpolation.create(config)); + } + + __attach(): void { + this._a.__addChild(this); + } + + __detach(): void { + this._a.__removeChild(this); + } +} + class AnimatedTransform extends AnimatedWithChildren { _transforms: Array; @@ -1233,6 +1260,14 @@ var multiply = function( return new AnimatedMultiplication(a, b); }; +var modulo = function( + a: Animated, + modulus: number +): AnimatedModulo { + return new AnimatedModulo(a, modulus); +}; + + var maybeVectorAnim = function( value: AnimatedValue | AnimatedValueXY, config: Object, @@ -1604,6 +1639,12 @@ module.exports = { */ multiply, + /** + * Creates a new Animated value that is the (non-negative) modulo of the + * provided Animated value + */ + modulo, + /** * Starts an animation after the given delay. */