Skip to content

Commit

Permalink
fix: tabs can not scroll at mobile, close #4828
Browse files Browse the repository at this point in the history
  • Loading branch information
tangjinzhou committed Nov 2, 2021
1 parent 9f5ac8d commit 42afcbb
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions components/tabs/src/hooks/useTouchMove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 42afcbb

Please sign in to comment.