mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 02:54:15 +00:00
🎨 Improve useLongPress
hook
This commit is contained in:
parent
68c577079c
commit
9329826ce3
@ -5,7 +5,7 @@ export default (
|
||||
onClick,
|
||||
{
|
||||
shouldPreventDefault = true,
|
||||
delay = 300,
|
||||
delay = app.cores.settings.get("longPressDelay") ?? 500,
|
||||
onTouchStart,
|
||||
onTouchEnd,
|
||||
} = {}
|
||||
@ -28,27 +28,35 @@ export default (
|
||||
}
|
||||
|
||||
timeout.current = setTimeout(() => {
|
||||
onLongPress(event)
|
||||
if (typeof onLongPress === "function") {
|
||||
onLongPress(event)
|
||||
}
|
||||
|
||||
setLongPressTriggered(true)
|
||||
}, delay)
|
||||
},
|
||||
[onLongPress, delay, shouldPreventDefault]
|
||||
)
|
||||
|
||||
const clear = useCallback(
|
||||
(event, shouldTriggerClick = true) => {
|
||||
timeout.current && clearTimeout(timeout.current)
|
||||
shouldTriggerClick && !longPressTriggered && onClick()
|
||||
setLongPressTriggered(false)
|
||||
const clear = useCallback((event, shouldTriggerClick = true) => {
|
||||
if (timeout.current) {
|
||||
clearTimeout(timeout.current)
|
||||
}
|
||||
|
||||
if (typeof onTouchEnd === "function") {
|
||||
onTouchEnd()
|
||||
}
|
||||
if (shouldTriggerClick && !longPressTriggered && typeof onClick === "function") {
|
||||
onClick()
|
||||
}
|
||||
|
||||
if (shouldPreventDefault && target.current) {
|
||||
target.current.removeEventListener("touchend", preventDefault)
|
||||
}
|
||||
},
|
||||
setLongPressTriggered(false)
|
||||
|
||||
if (typeof onTouchEnd === "function") {
|
||||
onTouchEnd()
|
||||
}
|
||||
|
||||
if (shouldPreventDefault && target.current) {
|
||||
target.current.removeEventListener("touchend", preventDefault)
|
||||
}
|
||||
},
|
||||
[shouldPreventDefault, onClick, longPressTriggered]
|
||||
)
|
||||
|
@ -1,4 +1,3 @@
|
||||
export { default as useLongPress } from "./useLongPress"
|
||||
export { default as findChildById } from "./findChildById"
|
||||
export { default as cursorPosition } from "./cursorPosition"
|
||||
export { default as getBase64 } from "./getBase64"
|
||||
|
Loading…
x
Reference in New Issue
Block a user