UI Patterns
Native-like

Gestures

Why gestures clash on the web and how native platforms decide which one wins — then long press menus, paged swiping, swipe actions and pull to refresh, built so they don't clash.

A single gesture is easy: listen to pointer events, move something. The trouble starts with the second one. Put a horizontal carousel inside a screen that swipes back, a list inside a sheet you can drag, a long-press menu on a row you can also swipe — and one finger now means several things at once. The pages after this one run into it again and again:

  • swipe back against any horizontal content on the screen, and against Safari's own back gesture;
  • the sheet's drag against its list's scrolling;
  • the click that fires when a drag ends over a button.

This page is the theory they build on: how native platforms decide which gesture wins, what the web gives you instead, and the tactics that close the gap — then four patterns built with them.

How native platforms decide

Native toolkits have a referee: something that sees every recognizer interested in a touch and decides which one gets it.

PlatformMechanism
UIKitrecognizers are state machines; require(toFail:) and delegate methods order them
SwiftUIgestures are composed: simultaneous, sequenced, exclusive
Flutterthe gesture arena: every recognizer for a pointer enters, one wins
Android (Views)a parent can intercept a child's touches; a child can forbid it
Android (Compose)nested scrolling passes leftover scroll from child to parent
React NativeGesture Handler brings the arena model to JS: competing, simultaneous, exclusive gestures

The defaults say a lot. UIKit "normally allows the recognition of only one gesture at a time on a single view", and its documentation gives the classic clash: "in a view that contains both pan and swipe gesture recognizers, swipes are never recognized" — the pan, being continuous, always wins first. Order is set explicitly: require(toFail:) is for when "you want a single-tap gesture require that a double-tap gesture fail". SwiftUI expresses the same through composition — "to require a long press before the user can drag a view, you sequence a DragGesture after a LongPressGesture".

Flutter's gesture arena is the clearest model. When more than one recognizer wants a pointer, each "join[s] the gesture arena", and:

At any time, a recognizer can eliminate itself and leave the arena. If there's only one recognizer left in the arena, that recognizer wins.

At any time, a recognizer can declare itself the winner, causing all of the remaining recognizers to lose.

For horizontal against vertical drag, both enter on pointer down; "if the user moves the pointer more than a certain number of logical pixels horizontally, the horizontal recognizer declares the win". Android Views do the same with touch slop — "the distance in pixels a user's touch can wander before the gesture is interpreted as scrolling" — and a parent that claims the gesture from onInterceptTouchEvent sends the child an ACTION_CANCEL.

What the web has

No referee. Every listener sees every pointer event, and the only negotiation is with the browser itself:

  • touch-action tells the browser which pans it may handle — pan-y leaves vertical scrolling to the browser and horizontal moves to you. It's read once: "After a gesture starts, changes to touch-action will not have any impact on the behavior of the current gesture."
  • pointercancel is the browser declaring itself the winner: "An application using Pointer events will receive a pointercancel event when the browser starts handling a touch gesture." Treat it as losing the arena, not as a release.
  • Pointer capture (setPointerCapture) routes the rest of a pointer's events to one element — the closest thing to winning.

Everything else is your code agreeing with your other code.

Tactics

Each of these maps to a native mechanism, and each is used somewhere on this site.

  1. A threshold, then an axis lock. Do nothing until the pointer has moved ~10 px, then commit to the axis it moved along and ignore the other. This is the arena's "declare the win", and Android's touch slop. Swipe back starts only on a mostly-horizontal move to the right; anything else is left to scrolling.

  2. Capture only after winning. Capturing the pointer on pointerdown claims it before you know it's yours — and retargets the click that a tap would have produced. Capture when the threshold is crossed. The sheet's Cancel and Done buttons stopped working until this was fixed.

  3. Edge zones. Accept the gesture only if it starts near an edge, like UIKit's UIScreenEdgePanGestureRecognizer. It shrinks the overlap to a strip — at the cost of discoverability, which is why iOS 26 added full-screen swipe back alongside it.

  4. Conditional hand-off. One gesture yields while a condition holds: the sheet's list scrolls unless it's at its top, then a downward pull moves the sheet. That's nested scrolling — the child uses the movement until it can't, then the parent takes over.

  5. Opt-out markers. Let an element say "not for you" to gestures above it, like Android's requestDisallowInterceptTouchEvent. Base UI's Drawer reads data-base-ui-swipe-ignore; your own gestures can check event.target.closest("[data-gesture-ignore]") before starting.

  6. Swallow the click after a drag. A drag that ends over a button fires its click. Cancel it in the capture phase when the pointer moved:

    element.addEventListener(
      "click",
      (event) => {
        if (!dragged) return;
        dragged = false;
        event.preventDefault();
        event.stopPropagation();
      },
      { capture: true },
    );
  7. Decide touch-action up front. Because it can't change mid-gesture, set it from state before the touch starts: the sheet's content is touch-action: none at the medium detent, where every drag moves the sheet, and pan-y at the large one, where the list scrolls.

A small arena

Once several custom gestures can start on the same element — swipe back, a carousel, row swipe actions — scattered if checks stop scaling. A shared owner per pointer is enough to get the arena's main rule, "one wins, the rest lose":

const owners = new Map<number, string>();

export const arena = {
  claim(pointerId: number, gesture: string) {
    const owner = owners.get(pointerId);
    if (owner && owner !== gesture) return false;
    owners.set(pointerId, gesture);
    return true;
  },
  owner(pointerId: number) {
    return owners.get(pointerId);
  },
  release(pointerId: number) {
    owners.delete(pointerId);
  },
};

Each gesture calls arena.claim() when its threshold is crossed and gives up if it returns false; every gesture checks arena.owner() before reacting; pointerup and pointercancel release. The browser is still the senior player — a pointercancel means it took the touch, whoever held the claim.

Or use a library

The tactics above are what gesture libraries package:

  • use-gesture (React DOM) exposes them as options: threshold, axis: 'lock' ("lock the movement of the gesture once a direction has been detected"), filterTaps ("won't trigger your drag logic if the user just clicked"), and preventScroll, "a convenient way to have both vertical drag and vertical scrolling coexist" — with the caveat that "scroll will always have precedence over drag". Its options configure one gesture at a time; deciding between separate gestures is still yours.
  • React Native Gesture Handler is a real arena: useCompetingGestures ("The first gesture to activate cancels the rest"), useSimultaneousGestures, useExclusiveGestures, and requireToFail / simultaneousWith / block between components — block being "especially useful for lists, where a ScrollView needs to wait for every gesture underneath it". It runs on the web through React Native for Web, so it fits a React Native app, not a plain React DOM site.

For one or two gestures, the tactics are enough. Past that, either adopt a library or write the arena on purpose, as above — not by accident, one if at a time.

Long press

Touch and hold a message, or right-click it:

This is Base UI's Context Menu as shipped. Its trigger already does what UIKit's long-press recognizer does by default — wait 0.5 s, and give up if the finger moves more than 10 px — straight from its source: LONG_PRESS_DELAY = 500 and a moveThreshold of 10 that cancels the timer. That cancellation is tactic 1 in action: once the finger travels, the touch is a scroll, and the long press leaves the arena. The same component opens on right-click, and it prevents the browser's own context menu on its trigger.

The demo skips accessibility

The long press is the only way to these actions here, as it often is in iOS apps. On the web that's bad practice: a long press is invisible, and the trigger isn't a focusable control, so keyboard and screen-reader users can't reach the actions at all. Apple's own rule is "Always make context menu items available in the main interface, too", and Base UI's documentation says "Don't make a context menu the only way to perform actions."

A good implementation adds a visible "⋯" button on each row that opens a regular menu with the same items — in Base UI a context-menu item and a menu item are the same component, so one list serves both — or puts the actions in a toolbar on the message's own screen, as Mail does.

iOS also plays a haptic tap when the press is recognized; the demo does the same with navigator.vibrate (see haptics in gestures). One thing it doesn't do: the touched row lifts out with a preview while the menu is open.

Swiping between pages

Onboarding screens, photo viewers and image galleries page horizontally, one screen per swipe:

No gesture code at all — CSS scroll snap hands the whole gesture to the browser, which brings native momentum and the platform's own feel for free:

.pager {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  overscroll-behavior-x: contain;
}
.page {
  flex: 0 0 100%;
  scroll-snap-align: center;
  scroll-snap-stop: always;
}
  • scroll-snap-stop: always stops at every page, so a hard flick moves one page, not three.
  • overscroll-behavior-x: contain keeps the last page's overscroll from chaining into whatever scrolls behind it.
  • The current page comes from the scroll position (Math.round(scrollLeft / clientWidth)); the dots and the Next button scroll with scrollTo(), smoothly unless reduced motion is on.

Because the browser owns this gesture, other gestures must yield to it. A full-screen swipe-back that starts on a pager is the clash UIKit avoided by keeping its edge-only recognizer: on a screen like this, only a swipe from the edge should mean "back".

For assistive technology the pager is a carousel, following the W3C pattern: "The carousel container has the aria-roledescription property set to carousel", and "each slide container has role group with the property aria-roledescription set to slide", named by its own heading. A "1 of 3" label is only the fallback when slides have no unique names — "normally, including set position and size information in an accessible name is not appropriate". The dots are buttons. Reach for a library such as Embla only for what scroll snap can't do — looping, autoplay, or keeping several synced views.

Swipe actions

Swipe a message left to reveal Archive and Delete, right to toggle read; swipe all the way to run the outermost action without tapping:

This one is hand-written. The libraries we tried either needed a whole UI framework (Ionic's IonItemSliding) or couldn't leave the buttons revealed on a phone-width row (react-swipeable-list: with full swipe on, every release either snapped back or fired the action). Most of the parts already exist on this site, and the demo is mostly the tactics above, combined:

  • Threshold, then axis lock (tactic 1). Nothing moves for the first 10 px; then a mostly-horizontal move becomes a swipe and the row captures the pointer, while a mostly-vertical one is left to scrolling, which keeps touch-action: pan-y.
  • One row open at a time — the small arena. The list holds the id of the row that owns the gesture; starting a swipe claims it, and every other row springs closed. A tap anywhere while a row is open only closes it, the way iOS does, and the tap goes no further.
  • Three ways to settle. Past 70% of the row's width, the outermost action stretches across the row and runs on release (a full swipe). The stretch is its own spring, from 0 to 1, mixed into the actions' widths: crossing the 70% line animates Delete over Archive, and backing off animates it back, instead of snapping. A flick faster than 500 px/s opens or closes in its direction. Otherwise the row opens if it's past half of the revealed actions' width. The settle is a spring that keeps the release speed, as on the Motion page; removing actions then collapse the row before the message disappears.
  • Swallow the click after a drag (tactic 6), so releasing over the row doesn't open the message.
  • An opt-out marker (tactic 5). Controls inside a row that react to a press carry data-swipe-ignore, and the row doesn't start swipes from them. An earlier version had a "⋯" button on each row; Base UI opens a menu on press, so a swipe that started on it opened the menu instead.

The clash it leaves to the screen around it is swipe back: a row swipe to the right and a full-screen swipe back are the same movement. On a screen with both, keep back to the edge zone and start row swipes away from it.

The demo skips accessibility

Like iOS, the demo offers these actions only by swiping, and the revealed buttons are hidden from assistive technology. On the web that's bad practice: swipes can't be performed from a keyboard, a switch or a screen reader. (iOS gets away with it because VoiceOver exposes a row's swipe actions as its "Actions" rotor; the web has no equivalent.)

A good implementation gives every row a visible "⋯" menu with the same actions — marked data-swipe-ignore, so swipes don't start on it — or puts the actions on the message's own screen.

Pull to refresh

Pull the list down past the top:

This one is hand-written too. We tried react-simple-pull-to-refresh first; it worked, but its animation was stiff and its "pull" text flickered while dragging. The iOS refresh control is a small set of behaviours:

  • A rubber band. The list follows the finger with growing resistance — 140 × (1 − 1 / (0.8 × distance / 140 + 1)) — so the first centimetre moves almost one-to-one and the pull can never go far.
  • The spinner assembles as you pull. Its eight spokes appear one by one with the pull's progress, so the user sees how far is left.
  • It starts at the threshold, not on release. Past 56 px of movement the refresh begins and the spinner turns, while the finger is still down.
  • It holds, then springs back. Released during a refresh, the list rests just below the spinner (48 px); when the refresh finishes, a spring takes it back to the top.
  • A haptic tick at the threshold, the moment the refresh starts, so the finger knows it can let go (see haptics in gestures).

The clash handling is the sheet's: a pull only starts when the list is scrolled to its top and the finger moves down; otherwise it's an ordinary scroll. On touch that needs a non-passive touchmove listener calling preventDefault() — the only way to keep the browser from scrolling once the pull has begun. The list also has overscroll-behavior-y: none, which removes both the native bounce and the browser's own pull-to-refresh (see Basics); otherwise the user would get two indicators and a page reload.

The demo skips accessibility

Pulling is the only way to refresh here, as in many iOS apps. On the web that's bad practice: a pull can't be done from a keyboard or a screen reader, and in an installed app there's no browser reload button to fall back on.

A good implementation adds a refresh button in the top bar that calls the same refresh function, and announces the result — the demo already says "Refreshing orders" and the update time through an invisible status region, which costs nothing visually.

Haptics in gestures

The long press and pull to refresh demos vibrate the way iOS does: a tap when the menu opens, a tick when the pull crosses the threshold. Like system haptics on iOS, they're on by default — part of the gesture, not an interface sound to opt into. They call navigator.vibrate (see Haptics), which limits where they work:

  • Not on iOS. Safari has no Vibration API. The workaround — a hidden <input type="checkbox" switch> toggled from script — was closed in iOS 26.5: the switch haptic now fires only on a direct tap, when the finger lifts. A long press and a pull need the haptic while the finger is still down, so there is no way to play it on an iPhone.
  • Not on the very first gesture. Chrome only vibrates after the user has activated the page, and a touch counts as activation only when the finger lifts. A long press or a pull is still in progress at the moment it vibrates, so if it's the first thing the user does on the page, it's silent; every gesture after the first tap buzzes.

Sources

On this page