Skip to content

Commit 42afcbb

Browse files
committed
fix: tabs can not scroll at mobile, close #4828
1 parent 9f5ac8d commit 42afcbb

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

components/tabs/src/hooks/useTouchMove.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,26 @@ export default function useTouchMove(
3333

3434
e.preventDefault();
3535
const { screenX, screenY } = e.touches[0];
36-
setTouchPosition({ x: screenX, y: screenY });
3736
const offsetX = screenX - touchPosition.value.x;
3837
const offsetY = screenY - touchPosition.value.y;
3938
onOffset(offsetX, offsetY);
39+
setTouchPosition({ x: screenX, y: screenY });
4040
const now = Date.now();
41-
setLastTimestamp(now);
4241
setLastTimeDiff(now - lastTimestamp.value);
42+
setLastTimestamp(now);
4343
setLastOffset({ x: offsetX, y: offsetY });
4444
}
4545

4646
function onTouchEnd() {
4747
if (!touchPosition.value) return;
48-
48+
const lastOffsetValue = lastOffset.value;
4949
setTouchPosition(null);
5050
setLastOffset(null);
5151

5252
// Swipe if needed
53-
if (lastOffset.value) {
54-
const distanceX = lastOffset.value.x / lastTimeDiff.value;
55-
const distanceY = lastOffset.value.y / lastTimeDiff.value;
53+
if (lastOffsetValue) {
54+
const distanceX = lastOffsetValue.x / lastTimeDiff.value;
55+
const distanceY = lastOffsetValue.y / lastTimeDiff.value;
5656
const absX = Math.abs(distanceX);
5757
const absY = Math.abs(distanceY);
5858

0 commit comments

Comments
 (0)