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
+1 -1
View File
@@ -101,7 +101,7 @@
</div>
<div class="row-2 ml-12">
{#if !isHead}
<ReplySummary {event} />
<ReplySummary {event} on:click={onClick} />
{/if}
<ReactionSummary {event} {onReactionClick} />
</div>
+2 -2
View File
@@ -10,8 +10,8 @@
</script>
{#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" />
{$replies.length}
</div>
</button>
{/if}
+16 -2
View File
@@ -1,15 +1,29 @@
<script lang="ts">
export let onLongPress
const onTouchStart = () => {
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: number
</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 />
</div>