BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/ericts-ui/use-swipe-navigation

useSwipeNavigation

ericts-ui/use-swipe-navigation
FreeHook

A touch-first React hook for previous and next navigation with direction locking, velocity thresholds, gesture ownership, and reduced-motion feedback.

Install it

npx shadcn@latest add https://ui.ericts.com/r/use-swipe-navigation.json

Source

registry/base/hooks/use-swipe-navigation.tsui.ericts.com/r/use-swipe-navigation.json · first 6 KB
1"use client";
2
3import { useCallback, useEffect, useRef } from "react";
4
5export type SwipeNavigationDirection = "previous" | "next";
6
7type SwipeState = {
8 touchIdentifier: number;
9 startX: number;
10 startY: number;
11 currentX: number;
12 currentY: number;
13 startedAt: number;
14 axis: "pending" | "horizontal" | "vertical";
15 reduceMotion: boolean;
16};
17
18export type UseSwipeNavigationOptions = {
19 onPrevious: () => void;
20 onNext: () => void;
21 hasPrevious?: boolean;
22 hasNext?: boolean;
23 disabled?: boolean;
24 ignoreOwnedGestures?: boolean;
25 onIntentChange?: (direction: SwipeNavigationDirection | null) => void;
26 distanceThreshold?: number;
27 velocityThreshold?: number;
28 directionLockThreshold?: number;
29 feedbackDistance?: number;
30};
31
32const DEFAULT_DISTANCE_THRESHOLD = 52;
33const DEFAULT_VELOCITY_THRESHOLD = 0.35;
34const DEFAULT_DIRECTION_LOCK_THRESHOLD = 8;
35const DEFAULT_FEEDBACK_DISTANCE = 16;
36const OWNED_GESTURE_SELECTOR = [
37 "input",
38 "textarea",
39 "select",
40 "[contenteditable]:not([contenteditable='false'])",
41 "[role='slider']",
42 "[draggable='true']",
43 "video[controls]",
44 "audio[controls]",
45 "[data-swipe-navigation='ignore']",
46].join(",");
47
48/**
49 * Recognizes one-finger horizontal touch gestures without taking over vertical
50 * scrolling. A non-passive touchmove listener lets nested horizontal controls
51 * keep their own gestures while the surrounding surface remains swipeable.
52 */
53export function useSwipeNavigation<T extends HTMLElement>({
54 onPrevious,
55 onNext,
56 hasPrevious = true,
57 hasNext = true,
58 disabled = false,
59 ignoreOwnedGestures = false,
60 onIntentChange,
61 distanceThreshold = DEFAULT_DISTANCE_THRESHOLD,
62 velocityThreshold = DEFAULT_VELOCITY_THRESHOLD,
63 directionLockThreshold = DEFAULT_DIRECTION_LOCK_THRESHOLD,
64 feedbackDistance = DEFAULT_FEEDBACK_DISTANCE,
65}: UseSwipeNavigationOptions) {
66 const elementRef = useRef<T>(null);
67 const swipeStateRef = useRef<SwipeState | null>(null);
68 const suppressClickRef = useRef(false);
69 const resetTimeoutRef = useRef<number | null>(null);
70
71 const clearResetTimeout = useCallback(() => {
72 if (resetTimeoutRef.current === null) return;
73
74 window.clearTimeout(resetTimeoutRef.current);
75 resetTimeoutRef.current = null;
76 }, []);
77
78 const clearFeedbackStyles = useCallback(() => {
79 const element = elementRef.current;
80
81 if (!element) return;
82
83 element.style.removeProperty("transition");
84 element.style.removeProperty("transform");
85 element.style.removeProperty("will-change");
86// … truncated

Files it writes

  • registry/base/hooks/use-swipe-navigation.ts

Facts

Registry
ericts-ui
Type
registry:hook
Access
Free
Files written
1
Licence
MIT
In the index
at or before 2026-08-15
Last confirmed
today

Go to the source

Docs on ericts-ui ui.ericts.com EricTsai83/ericts-ui on GitHub Raw registry item This item as JSON

More from ericts-ui

All 43 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
useElementHeightuse-element-heightericts-uiHooksFreeno deps
useElementSizeMapuse-element-size-mapericts-uiHooksFreeno deps
useReducedMotionuse-reduced-motionericts-uiHooksFreeno deps
useScrollAnchoruse-scroll-anchorericts-uiHooksFreeno deps
useScrollProgressuse-scroll-progressericts-uiHooksFreeno deps
useSequencePlayeruse-sequence-playerericts-uiHooksFreeno deps

Also from Kynth Studios

Built for the same person as BlockDex

SkillWorks

Claude Code skills and plugins, scored

skillworks.kynth.studio

RuleStack

AGENTS.md gallery and agent-config comparison

rulestack.kynth.studio

ToolDrift

What the AI coding tools changed last night

tooldrift.kynth.studio

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex