From d0492d02f0622b1c6e7bf8954685574bb34427cd Mon Sep 17 00:00:00 2001 From: xfy Date: Fri, 15 May 2026 16:29:24 +0800 Subject: [PATCH] =?UTF-8?q?Fix=20collapse=20drag=20not=20tracking=20finger?= =?UTF-8?q?=20=E2=80=94=20use=20dynamic=20dragRange=20based=20on=20actual?= =?UTF-8?q?=20height=20change?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The fixed DRAG_RANGE_DP=200dp caused the collapse progress to advance faster than the visual height change, making the calendar feel like it "outruns" the finger. Now dragRangePx is computed as (weeks-1)×rowHeight, matching the actual visual height delta during collapse so finger movement maps 1:1 to visual change. Co-Authored-By: Claude Opus 4.7 --- .../kotlin/plus/rua/project/ui/BottomCard.kt | 13 ++++++------- .../kotlin/plus/rua/project/ui/CalendarMonthView.kt | 11 ++++++++++- .../kotlin/plus/rua/project/ui/CalendarUtils.kt | 4 ++-- 3 files changed, 18 insertions(+), 10 deletions(-) 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 33f51bb..a1efeb3 100644 --- a/shared/src/commonMain/kotlin/plus/rua/project/ui/BottomCard.kt +++ b/shared/src/commonMain/kotlin/plus/rua/project/ui/BottomCard.kt @@ -16,7 +16,6 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color import androidx.compose.ui.input.pointer.pointerInput -import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.unit.dp import plus.rua.project.CalendarViewModel @@ -24,16 +23,16 @@ import plus.rua.project.CalendarViewModel * 底部卡片,折叠状态下支持垂直拖拽触发折叠动画。 * * @param viewModel 日历 ViewModel,用于读取折叠状态和驱动拖拽 + * @param dragRangePx 拖拽手势映射范围(像素),progress 从 0→1 对应手指移动此距离。 + * 应设为折叠时日历实际高度变化量 (weeks-1)×rowHeight,使拖拽跟手。 * @param modifier 外部布局修饰符 */ @Composable fun BottomCard( viewModel: CalendarViewModel, + dragRangePx: Float, modifier: Modifier = Modifier ) { - val density = LocalDensity.current - val dragRange = with(density) { DRAG_RANGE_DP.dp.toPx() } - Surface( modifier = modifier .fillMaxWidth() @@ -48,7 +47,7 @@ fun BottomCard( viewModel.onExpandDragEnd() } ) { _, dragAmount -> - val delta = -dragAmount / dragRange + val delta = -dragAmount / dragRangePx viewModel.onExpandDrag(delta) } } else { @@ -61,7 +60,7 @@ fun BottomCard( viewModel.onDragEnd() } ) { _, dragAmount -> - val delta = -dragAmount / dragRange + val delta = -dragAmount / dragRangePx viewModel.onDrag(delta) } } @@ -82,4 +81,4 @@ fun BottomCard( ) } } -} \ No newline at end of file +} diff --git a/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarMonthView.kt b/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarMonthView.kt index 4a61aca..db2288e 100644 --- a/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarMonthView.kt +++ b/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarMonthView.kt @@ -180,9 +180,18 @@ fun CalendarMonthView( } } - if (cardHeightPx > 0) { + // 拖拽范围 = 折叠时日历实际高度变化量 (weeks-1)×rowHeight,使手指移动与视觉变化 1:1 对应 + val dragRangeMinPx = with(density) { DRAG_RANGE_MIN_DP.dp.toPx() } + val dragRangePx = if (effectiveRowHeightPx > 0) { + maxOf((effectiveWeeks - 1) * effectiveRowHeightPx.toFloat(), dragRangeMinPx) + } else { + dragRangeMinPx + } + + if (cardHeightPx > 0) { BottomCard( viewModel = viewModel, + dragRangePx = dragRangePx, modifier = Modifier .fillMaxWidth() .height(with(density) { cardHeightPx.toDp() }) diff --git a/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarUtils.kt b/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarUtils.kt index 6b7bd2f..509a534 100644 --- a/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarUtils.kt +++ b/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarUtils.kt @@ -21,8 +21,8 @@ const val ROW_PADDING_DP = 6 /** 日历网格水平 padding (dp) */ const val HORIZONTAL_PADDING_DP = 16 -/** BottomCard 拖拽手势范围 (dp) */ -const val DRAG_RANGE_DP = 200 +/** BottomCard 拖拽手势范围最小值 (dp),防止行数少时 dragRange 过小 */ +const val DRAG_RANGE_MIN_DP = 100 /** 日历与 BottomCard 之间的间距 (dp):展开时 */ const val CARD_GAP_EXPANDED_DP = 24