diff --git a/src/api/Animated/AnimatedImplementation.js b/src/api/Animated/AnimatedImplementation.js index 07d31cc..5302930 100644 --- a/src/api/Animated/AnimatedImplementation.js +++ b/src/api/Animated/AnimatedImplementation.js @@ -736,6 +736,32 @@ class AnimatedMultiplication extends AnimatedWithChildren { } } +class AnimatedDivision extends AnimatedWithChildren { + constructor(a, b) { + super(); + this._a = a; + this._b = b; + } + + __getValue() { + return this._a.__getValue() / this._b.__getValue(); + } + + interpolate(config) { + return new AnimatedInterpolation(this, Interpolation.create(config)); + } + + __attach() { + this._a.__addChild(this); + this._b.__addChild(this); + } + + __detach() { + this._a.__removeChild(this); + this._b.__removeChild(this); + } +} + class AnimatedTransform extends AnimatedWithChildren { constructor(transforms) { super(); @@ -949,6 +975,10 @@ function add(a, b) { return new AnimatedAddition(a, b); } +function divide(a, b) { + return new AnimatedDivision(a, b); +} + function multiply(a, b) { return new AnimatedMultiplication(a, b); } @@ -1187,6 +1217,7 @@ const AnimatedImplementation = { spring, add, multiply, + divide, sequence, parallel, stagger, diff --git a/test/api/Animated.js b/test/api/Animated.js index 33ba7db..47966ee 100644 --- a/test/api/Animated.js +++ b/test/api/Animated.js @@ -24,3 +24,10 @@ describe('Animated.View', () => { expect(typeof setNativeProps).to.equal('function'); }); }); + +describe('Animated.divide', () => { + it('divides integers', () => { + const divided = Animated.divide(new Animated.Value(1), new Animated.Value(2)); + expect(divided.__getValue()).to.equal(0.5); + }); +});