Skip to content

Commit 81ee556

Browse files
mdvaccameta-codesync[bot]
authored andcommitted
Fix lint issues in SpringAnimation (#55364)
Summary: Pull Request resolved: #55364 Fixed multiple lint issues in SpringAnimation.kt: 1. FieldsBelowInit: Moved isAtRest and isOvershooting computed properties above the init block to follow Kotlin initialization order conventions. 2. MixedConditionalOperators: Added explicit parentheses to clarify operator precedence in boolean expressions mixing && and ||. changelog: [internal] internal Reviewed By: javache Differential Revision: D91738503 fbshipit-source-id: 9968dc5c07f8a1023ef1f700f4dca26321a5692c
1 parent f4f9e17 commit 81ee556

1 file changed

Lines changed: 19 additions & 19 deletions

File tree

  • packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/SpringAnimation.kt

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,24 @@ internal class SpringAnimation(config: ReadableMap) : AnimationDriver() {
4040
private var currentLoop = 0
4141
private var originalValue = 0.0
4242

43+
private val isAtRest: Boolean
44+
/**
45+
* check if the current state is at rest
46+
*
47+
* @return is the spring at rest
48+
*/
49+
get() =
50+
(abs(currentState.velocity) <= restSpeedThreshold &&
51+
(getDisplacementDistanceForState(currentState) <= displacementFromRestThreshold ||
52+
springStiffness == 0.0))
53+
54+
/* Check if the spring is overshooting beyond its target. */
55+
private val isOvershooting: Boolean
56+
get() =
57+
(springStiffness > 0 &&
58+
((startValue < endValue && currentState.position > endValue) ||
59+
(startValue > endValue && currentState.position < endValue)))
60+
4361
init {
4462
currentState.velocity = config.getDouble("initialVelocity")
4563
resetConfig(config)
@@ -98,24 +116,6 @@ internal class SpringAnimation(config: ReadableMap) : AnimationDriver() {
98116
private fun getDisplacementDistanceForState(state: PhysicsState): Double =
99117
abs(endValue - state.position)
100118

101-
private val isAtRest: Boolean
102-
/**
103-
* check if the current state is at rest
104-
*
105-
* @return is the spring at rest
106-
*/
107-
get() =
108-
(abs(currentState.velocity) <= restSpeedThreshold &&
109-
(getDisplacementDistanceForState(currentState) <= displacementFromRestThreshold ||
110-
springStiffness == 0.0))
111-
112-
/* Check if the spring is overshooting beyond its target. */
113-
private val isOvershooting: Boolean
114-
get() =
115-
(springStiffness > 0 &&
116-
(startValue < endValue && currentState.position > endValue ||
117-
startValue > endValue && currentState.position < endValue))
118-
119119
private fun advance(realDeltaTime: Double) {
120120
if (isAtRest) {
121121
return
@@ -167,7 +167,7 @@ internal class SpringAnimation(config: ReadableMap) : AnimationDriver() {
167167
// End the spring immediately if it is overshooting and overshoot clamping is enabled.
168168
// Also make sure that if the spring was considered within a resting threshold that it's now
169169
// snapped to its end value.
170-
if (isAtRest || overshootClampingEnabled && isOvershooting) {
170+
if (isAtRest || (overshootClampingEnabled && isOvershooting)) {
171171
// Don't call setCurrentValue because that forces a call to onSpringUpdate
172172
if (springStiffness > 0) {
173173
startValue = endValue

0 commit comments

Comments
 (0)