From bc14056d3e940dbafd668bcaa3d144557b233a89 Mon Sep 17 00:00:00 2001 From: Rene Luria Date: Fri, 28 Aug 2026 16:14:00 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20logique=20de=20d=C3=A9cision=20du=20swi?= =?UTF-8?q?pe-back?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/com/livrets/ui/SwipeBack.kt | 15 ++++++ .../com/livrets/ui/SwipeBackGestureTest.kt | 52 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 sharedUI/src/commonMain/kotlin/com/livrets/ui/SwipeBack.kt create mode 100644 sharedUI/src/commonTest/kotlin/com/livrets/ui/SwipeBackGestureTest.kt diff --git a/sharedUI/src/commonMain/kotlin/com/livrets/ui/SwipeBack.kt b/sharedUI/src/commonMain/kotlin/com/livrets/ui/SwipeBack.kt new file mode 100644 index 0000000..8166a3a --- /dev/null +++ b/sharedUI/src/commonMain/kotlin/com/livrets/ui/SwipeBack.kt @@ -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 + } +} diff --git a/sharedUI/src/commonTest/kotlin/com/livrets/ui/SwipeBackGestureTest.kt b/sharedUI/src/commonTest/kotlin/com/livrets/ui/SwipeBackGestureTest.kt new file mode 100644 index 0000000..2c9a035 --- /dev/null +++ b/sharedUI/src/commonTest/kotlin/com/livrets/ui/SwipeBackGestureTest.kt @@ -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, + ) + ) + } +}