Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

Commit

Permalink
Fix touch support
Browse files Browse the repository at this point in the history
  • Loading branch information
Dlurak committed Mar 2, 2024
1 parent de9e57c commit 7c927b7
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 18 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"prettier-plugin-svelte": "^2.10.1",
"svelte": "^4.0.5",
"svelte-check": "^3.4.3",
"svelte-dnd-action": "^0.9.40",
"tailwindcss": "^3.3.3",
"tslib": "^2.4.1",
"typescript": "^5.0.0",
Expand Down
30 changes: 14 additions & 16 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 22 additions & 1 deletion src/lib/preferences/NavigationItems.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
usedIdsSvocal.set(ids);
};
/** When this changes all items will reevualte their xoffset */
let reEvaluateEvent = 0;
$: {
// Todo: Fix that svocal bug
if (browser) saveToSvocal();
Expand Down Expand Up @@ -71,6 +74,21 @@
...it,
isDragged: false
}));
reEvaluateEvent++;
items = items.sort((a, b) => a.xOffset - b.xOffset);
}}
on:touch={(e) => {
e.preventDefault();

const draggedElement = items.find((i) => i.isDragged);
if (!draggedElement) return;

const { clientX } = e.detail.touch;

reEvaluateEvent++;
draggedElement.xOffset = clientX;

items = items.sort((a, b) => a.xOffset - b.xOffset);
}}
icon={item.boxIcon}
on:remove={() => {
Expand All @@ -79,15 +97,18 @@

items = items;
inactiveItems = [...inactiveItems, removed[0]];

reEvaluateEvent++;
}}
canBeRemoved={!!(items.length - 1)}
bind:reEvaluateEvent
/>
{/each}
</ul>
{#if inactiveItems.length}
<div>
<h5>
<I18n key="settings.nav.unused" />
<I18n key="settings.nav.unused" />
</h5>
<ul class="flex gap-2 flex-col">
{#each inactiveItems as item, index}
Expand Down
38 changes: 37 additions & 1 deletion src/lib/preferences/navigation/NavigationButton.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<script lang="ts">
import { createEventDispatcher, onMount } from 'svelte';
import { browser } from '$app/environment';
const dispatch = createEventDispatcher();
let thisEle: HTMLLIElement;
/** change this to reevaluate the xOffset */
export let reEvaluateEvent = 0;
export let icon: string;
export let isDragged = false;
Expand All @@ -16,7 +20,20 @@
xCoord = thisEle.getBoundingClientRect().x;
};
onMount(resetXCoord);
onMount(() => {
resetXCoord();
dispatch('mount', {
element: thisEle
});
});
$: {
if (browser && thisEle) {
resetXCoord();
}
reEvaluateEvent;
}
</script>

<svelte:window on:resize={resetXCoord} />
Expand All @@ -33,6 +50,25 @@
isDragged = false;
dispatch('dragend');
}}
on:touchstart={(e) => {
e.preventDefault();

isDragged = true;
dispatch('dragstart');
}}
on:touchmove={(e) => {
const touch = e.touches[0];

xCoord = touch.clientX;

dispatch('touch', { ...e, touch });
}}
on:touchend={(e) => {
e.preventDefault();

isDragged = false;
dispatch('dragend');
}}
bind:this={thisEle}
>
{#if showRemove}
Expand Down

0 comments on commit 7c927b7

Please sign in to comment.