Skip to content

Commit 541f8c6

Browse files
committed
fix: Not peventDefault of touchStart since it will prevent click event
1 parent 9bf2666 commit 541f8c6

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

examples/basic.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ interface Item {
66
id: string;
77
}
88

9-
const MyItem: React.FC<Item> = ({ id }, ref) => (
9+
const MyItem: React.ForwardRefRenderFunction<any, Item> = ({ id }, ref) => (
1010
<span
1111
ref={ref}
1212
style={{
@@ -18,6 +18,9 @@ const MyItem: React.FC<Item> = ({ id }, ref) => (
1818
boxSizing: 'border-box',
1919
display: 'inline-block',
2020
}}
21+
onClick={() => {
22+
console.log('Click:', id);
23+
}}
2124
>
2225
{id}
2326
</span>

src/hooks/useMobileTouchMove.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export default function useMobileTouchMove(
1919

2020
const onTouchMove = (e: TouchEvent) => {
2121
if (touchedRef.current) {
22+
e.preventDefault();
23+
2224
const currentY = Math.ceil(e.touches[0].pageY);
2325
let offsetY = touchYRef.current - currentY;
2426
touchYRef.current = currentY;
@@ -50,7 +52,6 @@ export default function useMobileTouchMove(
5052
if (e.touches.length === 1 && !touchedRef.current) {
5153
touchedRef.current = true;
5254
touchYRef.current = Math.ceil(e.touches[0].pageY);
53-
e.preventDefault();
5455

5556
elementRef.current = e.target as HTMLElement;
5657
elementRef.current.addEventListener('touchmove', onTouchMove);

0 commit comments

Comments
 (0)