Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3b45ac5

Browse files
committed
Test dampingRatio
df
1 parent aa4a619 commit 3b45ac5

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

‎library/src/uiTest/java/com.github.lcdsmao.springx/ViewPropertySpringAnimatorTest.kt‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ package com.github.lcdsmao.springx
33
import android.view.View
44
import androidx.dynamicanimation.animation.DynamicAnimation
55
import androidx.dynamicanimation.animation.FloatPropertyCompat
6+
import androidx.dynamicanimation.animation.SpringForce
67
import androidx.test.ext.junit.rules.ActivityScenarioRule
78
import com.google.common.truth.Truth
89
import io.mockk.mockk
910
import io.mockk.verify
11+
import io.mockk.verifySequence
1012
import org.junit.Before
13+
import org.junit.Ignore
1114
import org.junit.Rule
1215
import org.junit.Test
1316

@@ -162,6 +165,34 @@ abstract class ViewPropertySpringAnimatorTest : UiTest {
162165
Truth.assertThat(animView.translationX).isEqualTo(100f)
163166
}
164167

168+
@Test
169+
@Ignore("Fix the implementation of [ViewPropertySpringAnimator] to let this test pass")
170+
fun testDampingRatio() {
171+
val onEnd = mockk<(Int) -> Unit>(relaxed = true)
172+
val anim = animView.spring()
173+
.defaultDampingRatio(SpringForce.DAMPING_RATIO_NO_BOUNCY)
174+
.rotation(100f) {
175+
dampingRatio = SpringForce.DAMPING_RATIO_HIGH_BOUNCY
176+
onEnd { _, _, _, _ -> onEnd.invoke(2) }
177+
}
178+
.translationY(100f) {
179+
dampingRatio = SpringForce.DAMPING_RATIO_LOW_BOUNCY
180+
onEnd { _, _, _, _ -> onEnd.invoke(1) }
181+
}
182+
.translationX(100f) {
183+
onEnd { _, _, _, _ -> onEnd.invoke(0) }
184+
}
185+
.setListener(onEnd = { onEnd.invoke(3) })
186+
runOnMainThread { anim.start() }
187+
verify(exactly = 4, timeout = 1000L) { onEnd.invoke(any()) }
188+
verifySequence {
189+
onEnd.invoke(0)
190+
onEnd.invoke(1)
191+
onEnd.invoke(2)
192+
onEnd.invoke(3)
193+
}
194+
}
195+
165196
private fun <T : View> ViewPropertySpringAnimator<T>.animate(
166197
property: DynamicAnimation.ViewProperty,
167198
value: Float,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /