Skip to content

Commit 18e692d

Browse files
perf: cache easing interpolators as lazy singletons
Avoid allocating new PathInterpolator/LinearInterpolator per animation. Instances are shared across all EaseView instances via companion object.
1 parent 1599b15 commit 18e692d

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

android/src/main/java/com/ease/EaseView.kt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,20 @@ class EaseView(context: Context) : ReactViewGroup(context) {
5858
private val runningAnimators = mutableMapOf<String, ObjectAnimator>()
5959
private val runningSpringAnimations = mutableMapOf<DynamicAnimation.ViewProperty, SpringAnimation>()
6060

61-
// --- Easing interpolators ---
61+
// --- Easing interpolators (lazy singletons shared across all instances) ---
62+
companion object {
63+
private val INTERPOLATOR_EASE_IN by lazy { PathInterpolator(0.42f, 0f, 1.0f, 1.0f) }
64+
private val INTERPOLATOR_EASE_OUT by lazy { PathInterpolator(0.0f, 0.0f, 0.58f, 1.0f) }
65+
private val INTERPOLATOR_EASE_IN_OUT by lazy { PathInterpolator(0.42f, 0f, 0.58f, 1.0f) }
66+
private val INTERPOLATOR_LINEAR by lazy { LinearInterpolator() }
67+
}
68+
6269
private fun getInterpolator(easing: String): TimeInterpolator = when (easing) {
63-
"easeIn" -> PathInterpolator(0.42f, 0f, 1.0f, 1.0f)
64-
"easeOut" -> PathInterpolator(0.0f, 0.0f, 0.58f, 1.0f)
65-
"easeInOut" -> PathInterpolator(0.42f, 0f, 0.58f, 1.0f)
66-
"linear" -> LinearInterpolator()
67-
else -> PathInterpolator(0.42f, 0f, 0.58f, 1.0f)
70+
"easeIn" -> INTERPOLATOR_EASE_IN
71+
"easeOut" -> INTERPOLATOR_EASE_OUT
72+
"easeInOut" -> INTERPOLATOR_EASE_IN_OUT
73+
"linear" -> INTERPOLATOR_LINEAR
74+
else -> INTERPOLATOR_EASE_IN_OUT
6875
}
6976

7077
// --- Hardware layer management ---

0 commit comments

Comments
 (0)