From d0f4980e012097504f7a95e2ace494923fce1e87 Mon Sep 17 00:00:00 2001 From: xfy Date: Wed, 20 May 2026 14:14:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=BF=AB=E9=80=9F?= =?UTF-8?q?=E6=BB=91=E5=8A=A8=E6=97=B6=E6=8A=98=E5=8F=A0/=E5=B1=95?= =?UTF-8?q?=E5=BC=80=E5=A4=B1=E6=95=88=EF=BC=8C=E6=94=B9=E7=94=A8=20progre?= =?UTF-8?q?ss=20=E9=98=88=E5=80=BC=E5=88=A4=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除 velocity 判定:change.position 是本地坐标,卡片移动会导致 velocityTracker 计算的速度方向错误,快速滑动时被误判方向而回弹 - onDragEnd 改为 progress > 0.3f 判定折叠,onExpandDragEnd 改为 progress < 0.7f 判定展开 - 修复 onDrag/onExpandDrag 的 race condition:将 _collapseAnimatable.value 的读取从 launch 外部移到协程内部,避免快速滑动时多回调并发读到旧值 Co-Authored-By: Claude Opus 4.7 (1M context) --- .../kotlin/plus/rua/project/CalendarViewModel.kt | 16 ++++------------ .../kotlin/plus/rua/project/ui/BottomCard.kt | 2 -- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/shared/src/commonMain/kotlin/plus/rua/project/CalendarViewModel.kt b/shared/src/commonMain/kotlin/plus/rua/project/CalendarViewModel.kt index 0d99b69..63d32fc 100644 --- a/shared/src/commonMain/kotlin/plus/rua/project/CalendarViewModel.kt +++ b/shared/src/commonMain/kotlin/plus/rua/project/CalendarViewModel.kt @@ -180,8 +180,8 @@ class CalendarViewModel( * @param delta 拖拽增量,已归一化到 [0,1] 区间 */ fun onDrag(delta: Float) { - val old = _collapseAnimatable.value coroutineScope.launch { + val old = _collapseAnimatable.value val new = (old + delta).coerceIn(0f, 1f) _collapseAnimatable.snapTo(new) } @@ -197,11 +197,7 @@ class CalendarViewModel( fun onDragEnd(velocityDpPerSec: Float = 0f) { coroutineScope.launch { val progress = _collapseAnimatable.value - val shouldCollapse = when { - velocityDpPerSec > FLING_VELOCITY_THRESHOLD_DP -> true - velocityDpPerSec < -FLING_VELOCITY_THRESHOLD_DP -> false - else -> progress > COLLAPSE_THRESHOLD - } + val shouldCollapse = progress > 0.3f if (shouldCollapse) { _collapseAnimatable.animateTo( targetValue = 1f, @@ -223,8 +219,8 @@ class CalendarViewModel( * @param delta 拖拽增量,已归一化到 [0,1] 区间 */ fun onExpandDrag(delta: Float) { - val old = _collapseAnimatable.value coroutineScope.launch { + val old = _collapseAnimatable.value val new = (old + delta).coerceIn(0f, 1f) _collapseAnimatable.snapTo(new) } @@ -240,11 +236,7 @@ class CalendarViewModel( fun onExpandDragEnd(velocityDpPerSec: Float = 0f) { coroutineScope.launch { val progress = _collapseAnimatable.value - val shouldExpand = when { - velocityDpPerSec < -FLING_VELOCITY_THRESHOLD_DP -> true - velocityDpPerSec > FLING_VELOCITY_THRESHOLD_DP -> false - else -> progress < 1f - COLLAPSE_THRESHOLD - } + val shouldExpand = progress < 0.7f if (shouldExpand) { _collapseAnimatable.animateTo( targetValue = 0f, diff --git a/shared/src/commonMain/kotlin/plus/rua/project/ui/BottomCard.kt b/shared/src/commonMain/kotlin/plus/rua/project/ui/BottomCard.kt index 9946ec5..1c41994 100644 --- a/shared/src/commonMain/kotlin/plus/rua/project/ui/BottomCard.kt +++ b/shared/src/commonMain/kotlin/plus/rua/project/ui/BottomCard.kt @@ -72,7 +72,6 @@ fun BottomCard( detectVerticalDragGestures( onDragEnd = { val velocity = velocityTracker.calculateVelocity() - // 上滑为正(折叠方向),下拉为负(展开方向) val velocityDpPerSec = with(density) { -velocity.y.toDp().value } viewModel.onExpandDragEnd(velocityDpPerSec) }, @@ -89,7 +88,6 @@ fun BottomCard( detectVerticalDragGestures( onDragEnd = { val velocity = velocityTracker.calculateVelocity() - // 上滑为正(折叠方向),下拉为负(展开方向) val velocityDpPerSec = with(density) { -velocity.y.toDp().value } viewModel.onDragEnd(velocityDpPerSec) },