Skip to content

Commit

Permalink
Add Animated.divide
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Stanberry committed Aug 19, 2018
1 parent 8ac0d7f commit 3ff5428
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/api/Animated/AnimatedImplementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -1187,6 +1217,7 @@ const AnimatedImplementation = {
spring,
add,
multiply,
divide,
sequence,
parallel,
stagger,
Expand Down
7 changes: 7 additions & 0 deletions test/api/Animated.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit 3ff5428

Please sign in to comment.