Skip to content

Launch plan

Launch plan

Due Thursday

  • Draft the post
  • Record the clip
  • Schedule it

Drag the slider left past 120px, then let go

Work

When a swipe turns the page

Swipe back turns the page when the fingers lift, not when they cross 120px: the arrow fills with the pull, pops to 1.1× once armed, and pulling back first cancels.

A two-finger swipe in the Highlight window goes back or forward through its history, as a browser does. An arrow slides in from the edge it’ll go to and its ring fills as the fingers travel. At 120px it turns solid and pops to 1.1× on a stiff spring (stiffness 700, damping 30), so you feel the moment letting go would count. Past it the arrow keeps coming but resists, rubber-banding at most 16px further in, while the ring stays a linear gauge of the fingers.

The page turns on release, not on the threshold. Navigating the moment the fingers cross 120px takes the decision away mid-gesture; waiting for the lift means pulling back cancels, and the arrow springs off the edge (stiffness 500, damping 40). When it does turn, the arrow holds for 100ms to show it took, then fades over 180ms.

"use client"

import { useReducedMotion } from "../../_lib/use-reduced-motion"
import { canGo, useSwipeBack } from "../../_lib/use-swipe-back"
import { SwipeWindowArrow } from "./nested/arrow"
import { SwipeWindowFrame } from "./nested/frame"
import { SwipeWindowPage } from "./nested/page"
import { SwipeWindowTravel } from "./nested/travel"

/**
 * A window with three pages of history, opened on the last. The slider stands in for two fingers
 * (browsers keep that swipe for their own back): the arrow fills as it travels, turns solid past
 * 120px, and the page only turns when you let go, so sliding back first cancels.
 */
function SwipeWindow() {
  const reduced = useReducedMotion()
  const { view, navigate, bodyProps, sliderProps } = useSwipeBack()
  const closed = { back: !canGo(view.index, "back"), forward: !canGo(view.index, "forward") }
  const hint = closed.forward
    ? "Drag the slider left past 120px, then let go"
    : closed.back
      ? "Drag the slider right past 120px, then let go"
      : "Drag the slider either way past 120px, then let go"

  return (
    <div className="flex w-full max-w-[560px] flex-col items-center gap-6">
      <SwipeWindowFrame
        index={view.index}
        arrival={view.arrival}
        arrow={view.arrow}
        now={view.now}
        reduced={reduced}
        onNavigate={navigate}
        bodyProps={bodyProps}
      />
      <div className="flex flex-col items-center gap-3">
        <SwipeWindowTravel travel={view.travel} slider={sliderProps} closed={closed} />
        <p className="text-center font-mono text-xs text-ink-muted" aria-live="polite">{hint}</p>
      </div>
    </div>
  )
}

SwipeWindow.Frame = SwipeWindowFrame
SwipeWindow.Arrow = SwipeWindowArrow
SwipeWindow.Page = SwipeWindowPage
SwipeWindow.Travel = SwipeWindowTravel

export { SwipeWindow }
All entries