Handle touch move

This commit is contained in:
Jon Staab 2024-10-25 17:05:09 -07:00
parent c88b6da23f
commit 8e97dd0c69
3 changed files with 19 additions and 5 deletions

View file

@ -101,7 +101,7 @@
</div> </div>
<div class="row-2 ml-12"> <div class="row-2 ml-12">
{#if !isHead} {#if !isHead}
<ReplySummary {event} /> <ReplySummary {event} on:click={onClick} />
{/if} {/if}
<ReactionSummary {event} {onReactionClick} /> <ReactionSummary {event} {onReactionClick} />
</div> </div>

View file

@ -10,8 +10,8 @@
</script> </script>
{#if $replies.length > 0} {#if $replies.length > 0}
<div class="flex-inline btn btn-neutral btn-xs gap-1 rounded-full"> <button type="button" on:click class="flex-inline btn btn-neutral btn-xs gap-1 rounded-full">
<Icon icon="reply" /> <Icon icon="reply" />
{$replies.length} {$replies.length}
</div> </button>
{/if} {/if}

View file

@ -1,15 +1,29 @@
<script lang="ts"> <script lang="ts">
export let onLongPress export let onLongPress
const onTouchStart = () => { const onTouchStart = (event: any) => {
touch = event.touches[0]
timeout = setTimeout(onLongPress, 500) 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) const onTouchEnd = () => clearTimeout(timeout)
let touch: Touch
let timeout: number let timeout: number
</script> </script>
<div role="button" tabindex="0" on:click on:touchstart={onTouchStart} on:touchend={onTouchEnd} {...$$props}> <div role="button" tabindex="0" on:click on:touchstart={onTouchStart} on:touchmove={onTouchMove} on:touchend={onTouchEnd} {...$$props}>
<slot /> <slot />
</div> </div>