diff --git a/Libraries/Animated/src/AnimatedImplementation.js b/Libraries/Animated/src/AnimatedImplementation.js index 3039f887b..e7edc16a9 100644 --- a/Libraries/Animated/src/AnimatedImplementation.js +++ b/Libraries/Animated/src/AnimatedImplementation.js @@ -840,6 +840,64 @@ class AnimatedInterpolation extends AnimatedWithChildren { } } +class AnimatedAddition extends AnimatedWithChildren { + _a: Animated; + _b: Animated; + + constructor(a: Animated, b: Animated) { + super(); + this._a = a; + this._b = b; + } + + __getValue(): number { + return this._a.__getValue() + this._b.__getValue(); + } + + interpolate(config: InterpolationConfigType): AnimatedInterpolation { + return new AnimatedInterpolation(this, Interpolation.create(config)); + } + + __attach(): void { + this._a.__addChild(this); + this._b.__addChild(this); + } + + __detach(): void { + this._a.__removeChild(this); + this._b.__removeChild(this); + } +} + +class AnimatedMultiplication extends AnimatedWithChildren { + _a: Animated; + _b: Animated; + + constructor(a: Animated, b: Animated) { + super(); + this._a = a; + this._b = b; + } + + __getValue(): number { + return this._a.__getValue() * this._b.__getValue(); + } + + interpolate(config: InterpolationConfigType): AnimatedInterpolation { + return new AnimatedInterpolation(this, Interpolation.create(config)); + } + + __attach(): void { + this._a.__addChild(this); + this._b.__addChild(this); + } + + __detach(): void { + this._a.__removeChild(this); + this._b.__removeChild(this); + } +} + class AnimatedTransform extends AnimatedWithChildren { _transforms: Array; @@ -1161,6 +1219,20 @@ type CompositeAnimation = { stop: () => void; }; +var add = function( + a: Animated, + b: Animated +): AnimatedAddition { + return new AnimatedAddition(a, b); +}; + +var multiply = function( + a: Animated, + b: Animated +): AnimatedMultiplication { + return new AnimatedMultiplication(a, b); +}; + var maybeVectorAnim = function( value: AnimatedValue | AnimatedValueXY, config: Object, @@ -1521,6 +1593,17 @@ module.exports = { */ spring, + /** + * Creates a new Animated value composed from two Animated values added + * together. + */ + add, + /** + * Creates a new Animated value composed from two Animated values multiplied + * together. + */ + multiply, + /** * Starts an animation after the given delay. */