[RN] add Animated test for spring tracking

This commit is contained in:
Spencer Ahrens 2015-07-09 01:45:33 -07:00
parent 9b162d7659
commit 7d4b1877ae
2 changed files with 24 additions and 5 deletions

View File

@ -23,6 +23,7 @@ var invariant = require('invariant');
var flattenStyle = require('flattenStyle');
var rebound = require('rebound');
var requestAnimationFrame = require('requestAnimationFrame');
import type InterpolationConfigType from 'Interpolation';
@ -175,7 +176,7 @@ class TimingAnimation extends Animation {
this.__debouncedOnEnd({finished: true});
} else {
this._startTime = Date.now();
this._animationFrame = window.requestAnimationFrame(this.onUpdate.bind(this));
this._animationFrame = requestAnimationFrame(this.onUpdate.bind(this));
}
};
if (this._delay) {
@ -205,7 +206,7 @@ class TimingAnimation extends Animation {
(this._toValue - this._fromValue)
);
if (this.__active) {
this._animationFrame = window.requestAnimationFrame(this.onUpdate.bind(this));
this._animationFrame = requestAnimationFrame(this.onUpdate.bind(this));
}
}
@ -255,7 +256,7 @@ class DecayAnimation extends Animation {
this._onUpdate = onUpdate;
this.__onEnd = onEnd;
this._startTime = Date.now();
this._animationFrame = window.requestAnimationFrame(this.onUpdate.bind(this));
this._animationFrame = requestAnimationFrame(this.onUpdate.bind(this));
}
onUpdate(): void {
@ -274,7 +275,7 @@ class DecayAnimation extends Animation {
this._lastValue = value;
if (this.__active) {
this._animationFrame = window.requestAnimationFrame(this.onUpdate.bind(this));
this._animationFrame = requestAnimationFrame(this.onUpdate.bind(this));
}
}
@ -482,7 +483,7 @@ class SpringAnimation extends Animation {
this.__debouncedOnEnd({finished: true});
return;
}
this._animationFrame = window.requestAnimationFrame(this.onUpdate.bind(this));
this._animationFrame = requestAnimationFrame(this.onUpdate.bind(this));
}
stop(): void {

View File

@ -440,6 +440,24 @@ describe('Animated Vectors', () => {
value1.setValue({x: 3, y: 4});
expect(value2.__getValue()).toEqual({x: 3, y: 4});
});
it('should track with springs', () => {
var value1 = new Animated.ValueXY();
var value2 = new Animated.ValueXY();
Animated.spring(value2, {
toValue: value1,
tension: 3000, // faster spring for faster test
friction: 60,
}).start();
value1.setValue({x: 1, y: 1});
jest.runAllTimers();
expect(Math.round(value2.__getValue().x)).toEqual(1);
expect(Math.round(value2.__getValue().y)).toEqual(1);
value1.setValue({x: 2, y: 2});
jest.runAllTimers();
expect(Math.round(value2.__getValue().x)).toEqual(2);
expect(Math.round(value2.__getValue().y)).toEqual(2);
});
});
describe('Animated Listeners', () => {