From 42afcbbfbce2401a3beb88ff0f7841776997b96a Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Tue, 2 Nov 2021 21:23:31 +0800 Subject: [PATCH] fix: tabs can not scroll at mobile, close #4828 --- components/tabs/src/hooks/useTouchMove.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/components/tabs/src/hooks/useTouchMove.ts b/components/tabs/src/hooks/useTouchMove.ts index 231c0db8a4..da0d2aca8c 100644 --- a/components/tabs/src/hooks/useTouchMove.ts +++ b/components/tabs/src/hooks/useTouchMove.ts @@ -33,26 +33,26 @@ export default function useTouchMove( e.preventDefault(); const { screenX, screenY } = e.touches[0]; - setTouchPosition({ x: screenX, y: screenY }); const offsetX = screenX - touchPosition.value.x; const offsetY = screenY - touchPosition.value.y; onOffset(offsetX, offsetY); + setTouchPosition({ x: screenX, y: screenY }); const now = Date.now(); - setLastTimestamp(now); setLastTimeDiff(now - lastTimestamp.value); + setLastTimestamp(now); setLastOffset({ x: offsetX, y: offsetY }); } function onTouchEnd() { if (!touchPosition.value) return; - + const lastOffsetValue = lastOffset.value; setTouchPosition(null); setLastOffset(null); // Swipe if needed - if (lastOffset.value) { - const distanceX = lastOffset.value.x / lastTimeDiff.value; - const distanceY = lastOffset.value.y / lastTimeDiff.value; + if (lastOffsetValue) { + const distanceX = lastOffsetValue.x / lastTimeDiff.value; + const distanceY = lastOffsetValue.y / lastTimeDiff.value; const absX = Math.abs(distanceX); const absY = Math.abs(distanceY);