Skip to content

Commit 84c81d7

Browse files
feat: add excludeSelectors option for swipe gesture configuration
1 parent 4a4b470 commit 84c81d7

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

src/components/CryptoTracker.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,8 @@ onMount(async () => {
473473
}, {
474474
minSwipeDistance: 60,
475475
maxSwipeTime: 400,
476-
preventScroll: true
476+
preventScroll: true,
477+
excludeSelectors: ['.card'] // Excluir o card do gráfico dos gestos de swipe
477478
});
478479
console.log('Swipe gestures configurados para', config.name);
479480
}

src/lib/swipe-gestures.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export interface SwipeConfig {
55
minSwipeDistance: number;
66
maxSwipeTime: number;
77
preventScroll: boolean;
8+
excludeSelectors?: string[]; // Seletores CSS de elementos a serem excluídos
89
}
910

1011
export interface SwipeCallbacks {
@@ -23,7 +24,8 @@ interface TouchPoint {
2324
const DEFAULT_CONFIG: SwipeConfig = {
2425
minSwipeDistance: 50, // Minimum distance in pixels for a valid swipe
2526
maxSwipeTime: 300, // Maximum time in ms for a valid swipe
26-
preventScroll: true // Prevent vertical scrolling during horizontal swipes
27+
preventScroll: true, // Prevent vertical scrolling during horizontal swipes
28+
excludeSelectors: [] // Selectors to exclude from swipe detection
2729
};
2830

2931
export function setupSwipeGestures(
@@ -45,6 +47,18 @@ export function setupSwipeGestures(
4547
}
4648

4749
function handleTouchStart(event: TouchEvent) {
50+
// Check if touch started on an excluded element
51+
if (finalConfig.excludeSelectors && finalConfig.excludeSelectors.length > 0) {
52+
const target = event.target as HTMLElement;
53+
for (const selector of finalConfig.excludeSelectors) {
54+
if (target.closest(selector)) {
55+
// Touch started on excluded element, ignore this gesture
56+
startTouch = null;
57+
return;
58+
}
59+
}
60+
}
61+
4862
startTouch = getTouchPoint(event);
4963
isHorizontalSwipe = false;
5064
callbacks.onSwipeStart?.(event);

0 commit comments

Comments
 (0)