forked from coracle/flotilla
Replace long press with tap target
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
<script lang="ts">
|
||||
const {children, onLongPress, ...restProps} = $props()
|
||||
|
||||
const ontouchstart = (event: any) => {
|
||||
touch = event.touches[0]
|
||||
timeout = setTimeout(onLongPress, 500)
|
||||
}
|
||||
|
||||
const ontouchmove = (event: any) => {
|
||||
const curTouch = event.touches[0]
|
||||
|
||||
if (Math.abs(curTouch.clientX - touch.clientX) > 30) {
|
||||
clearTimeout(timeout)
|
||||
}
|
||||
|
||||
if (Math.abs(curTouch.clientY - touch.clientY) > 30) {
|
||||
clearTimeout(timeout)
|
||||
}
|
||||
}
|
||||
|
||||
const ontouchend = () => clearTimeout(timeout)
|
||||
|
||||
let touch: Touch
|
||||
let timeout: any
|
||||
</script>
|
||||
|
||||
<div role="button" tabindex="0" {ontouchstart} {ontouchmove} {ontouchend} {...restProps}>
|
||||
{@render children()}
|
||||
</div>
|
||||
@@ -0,0 +1,15 @@
|
||||
<script lang="ts">
|
||||
import {isMobile} from "@lib/html"
|
||||
|
||||
const {children, onTap, ...restProps} = $props()
|
||||
|
||||
const onclick = (event: MouseEvent) => {
|
||||
if (isMobile) {
|
||||
onTap(event)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div role="button" tabindex="0" {onclick} {...restProps}>
|
||||
{@render children()}
|
||||
</div>
|
||||
Reference in New Issue
Block a user