Skip to content

Commit 02e6356

Browse files
author
Adam Miskiewicz
committed
Fix JS nits
1 parent 277a243 commit 02e6356

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

Libraries/Animated/src/animations/SpringAnimation.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ class SpringAnimation extends Animation {
6565
_overshootClamping: boolean;
6666
_restDisplacementThreshold: number;
6767
_restSpeedThreshold: number;
68-
_initialVelocity: ?number;
6968
_lastVelocity: number;
7069
_startPosition: number;
7170
_lastPosition: number;
7271
_fromValue: number;
7372
_toValue: any;
74-
_stiffness: ?number;
75-
_damping: ?number;
76-
_mass: ?number;
73+
_stiffness: number;
74+
_damping: number;
75+
_mass: number;
76+
_initialVelocity: number;
7777
_delay: number;
7878
_timeout: any;
7979
_startTime: number;
@@ -145,6 +145,10 @@ class SpringAnimation extends Animation {
145145
this._damping = springConfig.damping;
146146
this._mass = 1;
147147
}
148+
149+
invariant(this._stiffness > 0, 'Stiffness value must be greater than 0');
150+
invariant(this._damping > 0, 'Damping value must be greater than 0');
151+
invariant(this._mass > 0, 'Mass value must be greater than 0');
148152
}
149153

150154
__getNativeAnimationConfig() {
@@ -243,20 +247,13 @@ class SpringAnimation extends Animation {
243247
now = this._lastTime + MAX_STEPS;
244248
}
245249

246-
let deltaTime = 0.0;
247-
if (now > this._lastTime) {
248-
deltaTime = (now - this._lastTime) / 1000;
249-
}
250+
const deltaTime = (now - this._lastTime) / 1000;
250251
this._frameTime += deltaTime;
251252

252-
const c: number = this._damping || 0;
253-
const m: number = this._mass || 0;
254-
const k: number = this._stiffness || 0;
255-
const v0: number = -(this._initialVelocity || 0);
256-
257-
invariant(m > 0, 'Mass value must be greater than 0');
258-
invariant(k > 0, 'Stiffness value must be greater than 0');
259-
invariant(c > 0, 'Damping value must be greater than 0');
253+
const c: number = this._damping;
254+
const m: number = this._mass;
255+
const k: number = this._stiffness;
256+
const v0: number = -this._initialVelocity;
260257

261258
const zeta = c / (2 * Math.sqrt(k * m)); // damping ratio
262259
const omega0 = Math.sqrt(k / m); // undamped angular frequency of the oscillator (rad/ms)

Libraries/NativeAnimation/Drivers/RCTSpringAnimation.m

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,6 @@ - (void)stepAnimationWithTime:(NSTimeInterval)currentTime
129129
CGFloat k = _stiffness;
130130
CGFloat v0 = -_initialVelocity;
131131

132-
NSParameterAssert(m > 0);
133-
NSParameterAssert(k > 0);
134-
NSParameterAssert(c > 0);
135-
136132
CGFloat zeta = c / (2 * sqrtf(k * m));
137133
CGFloat omega0 = sqrtf(k / m);
138134
CGFloat omega1 = omega0 * sqrtf(1.0 - (zeta * zeta));

0 commit comments

Comments
 (0)