feat: logique de décision du swipe-back
This commit is contained in:
2 files changed
+67
No files matched your search
@@ -0,0 +1,15 @@
|
||||
package com.livrets.ui
|
||||
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
object SwipeBackGesture {
|
||||
val EdgeZone = 24.dp
|
||||
const val CommitRatio = 0.4f
|
||||
const val CommitVelocityDpPerSec = 1000f
|
||||
|
||||
fun shouldCommit(offsetPx: Float, containerWidthPx: Float, velocityDpPerSec: Float): Boolean {
|
||||
if (containerWidthPx <= 0f) return false
|
||||
return offsetPx / containerWidthPx > CommitRatio ||
|
||||
velocityDpPerSec >= CommitVelocityDpPerSec
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.livrets.ui
|
||||
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertFalse
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class SwipeBackGestureTest {
|
||||
|
||||
@Test
|
||||
fun `commit si l offset depasse 40 pourcent de la largeur`() {
|
||||
assertTrue(
|
||||
SwipeBackGesture.shouldCommit(
|
||||
offsetPx = 401f,
|
||||
containerWidthPx = 1000f,
|
||||
velocityDpPerSec = 0f,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `pas de commit si offset et velocite sous les seuils`() {
|
||||
assertFalse(
|
||||
SwipeBackGesture.shouldCommit(
|
||||
offsetPx = 399f,
|
||||
containerWidthPx = 1000f,
|
||||
velocityDpPerSec = 999f,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `commit par velocite seule meme avec offset nul`() {
|
||||
assertTrue(
|
||||
SwipeBackGesture.shouldCommit(
|
||||
offsetPx = 0f,
|
||||
containerWidthPx = 1000f,
|
||||
velocityDpPerSec = 1000f,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `pas de commit si la largeur n est pas connue`() {
|
||||
assertFalse(
|
||||
SwipeBackGesture.shouldCommit(
|
||||
offsetPx = 500f,
|
||||
containerWidthPx = 0f,
|
||||
velocityDpPerSec = 2000f,
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user