-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(packages): eix tab can't click on mobile side
- Loading branch information
Showing
6 changed files
with
123 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useState } from 'react'; | ||
|
||
type OnClick = () => void; | ||
|
||
export function useTap(onClick: OnClick) { | ||
const [touchStart, setTouchStart] = useState(false); | ||
|
||
// 处理触摸开始事件 | ||
const handleTouchStart = () => { | ||
setTouchStart(true); | ||
}; | ||
|
||
// 处理触摸结束事件 | ||
const handleTouchEnd = () => { | ||
// 判断触摸开始的状态,确保这是一个点击事件,而不是滑动等其他触摸事件 | ||
if (touchStart) { | ||
onClick(); | ||
} | ||
|
||
// 重置触摸状态 | ||
setTouchStart(false); | ||
}; | ||
|
||
const handleTouchMove = () => { | ||
// 触摸移动,认为不是点击事件 | ||
setTouchStart(false); | ||
}; | ||
|
||
return { | ||
onTouchStart: handleTouchStart, | ||
onTouchEnd: handleTouchEnd, | ||
onTouchMove: handleTouchMove | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters