🎨 Improve useLongPress hook

This commit is contained in:
SrGooglo 2023-05-09 21:36:11 +00:00
parent 68c577079c
commit 9329826ce3
2 changed files with 22 additions and 15 deletions

View File

@ -5,7 +5,7 @@ export default (
onClick,
{
shouldPreventDefault = true,
delay = 300,
delay = app.cores.settings.get("longPressDelay") ?? 500,
onTouchStart,
onTouchEnd,
} = {}
@ -28,17 +28,25 @@ export default (
}
timeout.current = setTimeout(() => {
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()
const clear = useCallback((event, shouldTriggerClick = true) => {
if (timeout.current) {
clearTimeout(timeout.current)
}
if (shouldTriggerClick && !longPressTriggered && typeof onClick === "function") {
onClick()
}
setLongPressTriggered(false)
if (typeof onTouchEnd === "function") {

View File

@ -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"