Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
update() {
const { stiffness, damping, mass, from, to, restSpeed, restDisplacement } = this.props;
const { delta, initialVelocity } = this;
const timeDelta = timeSinceLastFrame() / 1000;
const t = this.t = this.t + timeDelta;
const dampingRatio = damping / (2 * Math.sqrt(stiffness * mass));
const angularFreq = Math.sqrt(stiffness / mass);
const expoDecay = angularFreq * Math.sqrt(1.0 - (dampingRatio * dampingRatio));
const x0 = 1;
let oscillation = 0.0;
// Underdamped
if (dampingRatio < 1) {
const envelope = Math.exp(-dampingRatio * angularFreq * t);
oscillation = envelope * (((initialVelocity + dampingRatio * angularFreq * x0) / expoDecay) * Math.sin(expoDecay * t) + (x0 * Math.cos(expoDecay * t)));
this.velocity = (envelope * ((Math.cos(expoDecay * t) * (initialVelocity + dampingRatio * angularFreq * x0)) - (expoDecay * x0 * Math.sin(expoDecay * t))) -
((dampingRatio * angularFreq * envelope) * ((((Math.sin(expoDecay * t) * (initialVelocity + dampingRatio * angularFreq * x0)) ) / expoDecay) + (x0 * Math.cos(expoDecay * t)))));
update() {
const { autoStopSpeed, acceleration, friction, velocity, spring, to } = this.props;
let newVelocity = velocity;
const elapsed = timeSinceLastFrame();
// Apply acceleration to velocity
if (acceleration) {
newVelocity += speedPerFrame(acceleration, elapsed);
}
// Apply friction to velocity
if (friction) {
newVelocity *= (1 - friction) ** (elapsed / 100);
}
if (spring && to !== undefined) {
const distanceToTarget = to - this.current;
newVelocity += distanceToTarget * speedPerFrame(spring, elapsed);
}
const updateTween = () => {
elapsed += timeSinceLastFrame();
// const progress = clampProgress(getProgressFromValue(0, duration, elapsed));
// const current = getValueFromProgress(from, to, ease(progress));
update(elapsed);
};
getVelocity: () => {
const frame = currentFrameTime();
const frameDelta = timeSinceLastFrame();
return (frame - lastUpdateTimestamp <= frameDelta)
? speedPerSecond(current - prev, frameDelta)
: 0;
},
update: (v: number) => {
scheduledUpdate = () => {
this.lastUpdated = timeSinceLastFrame();
this.prev = this.current;
const { onUpdate, passive } = this.props;
if (this.update) {
this.current = this.update(this.current);
}
if (onUpdate) {
onUpdate(this.get(), this);
}
this.fireListeners();
if (!passive && this._isActive) {
onFrameUpdate(this.scheduledUpdate);
update() {
const { autoStopDelta, timeConstant } = this.props;
this.elapsed += timeSinceLastFrame();
const delta = -this.amplitude * Math.exp(-this.elapsed / timeConstant);
const isMoving = (delta > autoStopDelta || delta < -autoStopDelta);
if (!isMoving) this.isComplete = true;
return isMoving ? this.target + delta : this.target;
}
update() {
const { duration, ease, from, to, playDirection } = this.props;
if (!this.isManualUpdate) {
this.elapsed += timeSinceLastFrame() * playDirection;
}
this.isManualUpdate = false;
this.progress = clampProgress(getProgressFromValue(0, duration, this.elapsed));
return getValueFromProgress(from, to, ease(this.progress));
}
ValueReaction.prototype.update = function (v) {
_super.prototype.update.call(this, v);
this.prev = this.current;
this.current = v;
this.timeDelta = framesync_1.timeSinceLastFrame();
};
ValueReaction.prototype.subscribe = function (observerCandidate) {
tweenTimer = onFrame().start((i) => {
elapsed += timeSinceLastFrame() * playDirection;
updateTween();
if (isTweenComplete() && complete) {
tweenTimer.stop();
onFrameUpdate(complete, true);
}
});
};