---
name: gesture-physics
description: Use when building drag, swipe, pull, fling and pinch interactions that need natural physics such as momentum, rubber-banding and snapping.
---

# Gesture physics

Things the user touches should follow the finger exactly, then hand off to physics when let go.

## Principles

1. **1:1 tracking**: while dragging, the element moves exactly with the pointer. No easing during the drag.
2. **Velocity handoff**: on release, start a spring or decay with the finger's velocity.
3. **Rubber-banding**: past a limit, resistance grows: `offset = limit + (overshoot * 0.55)` or `1 - 1 / (x * 0.55 / d + 1)` scaled.
4. **Projection**: decide where to snap using the projected end point, `end = position + velocity * 0.2`, not just the release point.
5. **Interruptible**: touching an element mid-animation catches it where it is.

## Swipe to dismiss

- Dismiss if dragged past 30-40% of the size or flung faster than about 800px/s.
- Rotate cards slightly with horizontal drag (about 10deg at the edge).
- Otherwise spring back (stiffness 400, damping 30).

## Bottom sheets

- Detents at about 30%, 60% and 95% of the screen height; snap to the nearest projected detent.
- Dim the background in proportion to the sheet height.

## Carousels

- Snap per item with scroll snapping where possible (`scroll-snap-type: x mandatory`).
- Custom carousels: decay with friction, then spring to the nearest item.

## Tools

- Web: Framer Motion `drag` with `dragConstraints`, `dragElastic` and `onDragEnd` velocity, or pointer events with `setPointerCapture`.
- React Native: Gesture Handler plus Reanimated `withSpring` and `withDecay`, running on the UI thread.
- SwiftUI: `DragGesture` with `predictedEndTranslation` and spring animations.

## Accessibility

- Every gesture needs a button or keyboard alternative.
- Add light haptics at snap points on mobile.
