From c6377d85f97294fb2f96d1120b3274cad2f8e72b Mon Sep 17 00:00:00 2001 From: xfy Date: Thu, 23 Jul 2026 14:39:27 +0800 Subject: [PATCH] =?UTF-8?q?perf(ui):=20=E4=BC=98=E5=8C=96=E5=A4=9A?= =?UTF-8?q?=E9=80=89=E4=B8=8E=E9=95=BF=E6=8C=89=E6=8B=96=E6=8B=BD=E7=81=B5?= =?UTF-8?q?=E6=95=8F=E5=BA=A6=EF=BC=8C=E5=AE=9E=E7=8E=B0=E6=9E=81=E9=80=9F?= =?UTF-8?q?=E5=93=8D=E5=BA=94=E8=B7=A8=E8=A1=8C=E8=BF=9E=E7=BB=AD=E5=A4=9A?= =?UTF-8?q?=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plus/rua/project/ui/DateRecorderScreen.kt | 50 ++++++++----------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/core/src/main/kotlin/plus/rua/project/ui/DateRecorderScreen.kt b/core/src/main/kotlin/plus/rua/project/ui/DateRecorderScreen.kt index 6fcd067..2bed6bb 100644 --- a/core/src/main/kotlin/plus/rua/project/ui/DateRecorderScreen.kt +++ b/core/src/main/kotlin/plus/rua/project/ui/DateRecorderScreen.kt @@ -377,33 +377,12 @@ private fun RecordGrid( val down = awaitFirstDown(pass = PointerEventPass.Initial, requireUnconsumed = false) val startOffset = down.position val startIndex = findItemIndexAtOffset(gridState, startOffset) ?: return@awaitEachGesture + val startTime = down.uptimeMillis var isDragSelecting = false + var isScrolling = false val initialSelected = if (selectionMode) selectedIds else emptySet() - if (!selectionMode) { - // 普通模式下:等待 300ms 长按判定 - val longPressResult = withTimeoutOrNull(300L) { - while (true) { - val event = awaitPointerEvent(pass = PointerEventPass.Initial) - val change = event.changes.firstOrNull { it.id == down.id } ?: break - if (!change.pressed) return@withTimeoutOrNull false - if ((change.position - startOffset).getDistance() > 20f) { - // 移动距离大于 20px 判定为滚屏而非长按 - return@withTimeoutOrNull false - } - } - true - } - if (longPressResult == null) { - // 300ms 超时到达且未松手/未远移,触发长按多选 - isDragSelecting = true - val startId = records[startIndex].id - onSetSelectedIds(setOf(startId)) - } - } - - // 持续监听 Pointer 移动手势 while (true) { val event = awaitPointerEvent(pass = PointerEventPass.Initial) val pointerChange = event.changes.firstOrNull { it.id == down.id } ?: break @@ -411,12 +390,25 @@ private fun RecordGrid( val currentOffset = pointerChange.position val distance = (currentOffset - startOffset).getDistance() + val elapsedTime = pointerChange.uptimeMillis - startTime - if (!isDragSelecting) { - if (selectionMode && distance > 10f) { - isDragSelecting = true - val startId = records[startIndex].id - onSetSelectedIds(initialSelected + startId) + if (!isDragSelecting && !isScrolling) { + if (selectionMode) { + // 多选模式下:滑动超过 6px 立刻触发极速滑动多选 + if (distance >= 6f) { + isDragSelecting = true + val startId = records[startIndex].id + onSetSelectedIds(initialSelected + startId) + } + } else { + // 普通模式下:按住满 250ms 或按住移动超过 10px(且未快滑滚屏)触发长按多选 + if (distance > 30f && elapsedTime < 200L) { + isScrolling = true // 快速划过判定为普通滚屏 + } else if (elapsedTime >= 250L || (elapsedTime >= 150L && distance >= 10f)) { + isDragSelecting = true + val startId = records[startIndex].id + onSetSelectedIds(setOf(startId)) + } } } @@ -433,7 +425,7 @@ private fun RecordGrid( // 边界滑动自动滚屏 val viewportHeight = gridState.layoutInfo.viewportSize.height if (currentOffset.y < 120f) { - coroutineScope.launch { gridState.scrollBy(-25f) } + coroutineScope.launch { gridState.scrollBy(-30f) } } else if (currentOffset.y > viewportHeight - 120f) { coroutineScope.launch { gridState.scrollBy(25f) } }