Skip to content

feat(staged): pinch to open and close note images on mobile web - #1093

Merged
matt2e merged 2 commits into
mainfrom
multi-touch-to-open-close-images
Nov 20, 2026
Merged

matt2e merged 2 commits into
mainfrom
multi-touch-to-open-close-images

Conversation

@matt2e

@matt2e matt2e commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Summary

On mobile web, a pinch-out on an inline note or chat image now opens it in the full screen viewer, and a pinch-in from the fitted size closes it. Both follow the fingers: the picture moves between its place in the note and the fit while the viewer's backdrop and header fade with the gesture.

Opening

  • A recogniser on the markdown container (mediaPinch.ts) takes two-finger touches where at least one finger is on an image. It prevents the moves and Safari's gesture events, so the page no longer zooms and a pinch-in no longer opens the tab overview.
  • Once the fingers spread it mounts the viewer with the picture laid exactly over the inline image and feeds it the gesture through a new programmatic setTransform on the zoom controller. The dialog's slide animation is off on this path.
  • On release the viewer settles at the fit, returns the picture to the note when the pinch was let go early, or stays at the scale under the fingers when the pinch went past the fit (settleTransform).
  • Once two fingers are down the recogniser also follows the sequence on the touch targets themselves, so a finger outside the container or a touched element removed mid-gesture cannot leave it holding a gesture and blocking later one-finger scrolls.

Closing

  • The zoom controller gains an opt-in pinchDismiss option, turned on only by the image viewer. A touch gesture that starts at the fit may go below it, reporting progress; on release it closes past a threshold (or on a quick pinch) and springs back to the fit otherwise.
  • A pinch-in that starts zoomed in meets a rubber band at the fitted size (up to a fifth of the fit, with growing resistance) and springs back on release. It never closes within that gesture.
  • A cancelled touch sequence (touchcancel) does not close the viewer.
  • When the inline image is only partly in view, the picture closes into the visible part, clipped, instead of landing on top of the note header or chat composer. With nowhere to return to, it shrinks about its centre and fades.

Unchanged

The diagram viewer and wheel zoom behave as before. Tap and the expand button still open the viewer with the usual animation.

touch-action: pan-x pan-y on the figure is deliberately not used: in Mobile Safari on the iOS 27.2 simulator it stopped a one-finger drag that starts on the image from scrolling the note, and preventing the events is enough to hold page zoom at 1.00x.

Tests

  • mediaPinch.test.ts: the opening recogniser, including its stuck states.
  • diagramZoom.test.ts: pinch dismiss, the rubber band, touchcancel, setTransform and settleTransform.
  • MediaViewerModal.component.test.ts: where the picture goes when a pinch ends (back to the image, clipped, shrink and fade, cancelled, and the opening outcomes).

🤖 Generated with Claude Code

matt2e and others added 2 commits November 19, 2026 16:41
A pinch-out on an inline note or chat image now opens it in the full
screen viewer, and a pinch-in from the fitted size closes it. Both
follow the fingers: the picture moves between its place in the note and
the fit while the viewer's backdrop and header fade with the gesture.

Opening. A recogniser on the markdown container (mediaPinch.ts) takes
two-finger touches where at least one finger is on an image. It prevents
the moves and Safari's gesture events, so the page no longer zooms and a
pinch-in no longer opens the tab overview. Once the fingers spread it
mounts the viewer with the picture laid exactly over the inline image
and feeds it the gesture through a new programmatic setTransform on the
zoom controller. The dialog's slide animation is off on this path. On
release the viewer settles at the fit, or returns the picture to the
note when the pinch was let go early.

Closing. The zoom controller gains an opt-in pinchDismiss option. A
touch gesture that starts at the fit may go below it, unconstrained,
reporting progress; on release it closes past a threshold (or on a quick
pinch) and springs back to the fit otherwise. A gesture that starts
zoomed in stops at the fit and never closes, so zooming back out cannot
overshoot into a close. With nowhere to return to (the inline image is
out of view) the picture shrinks about its centre and fades.

Only the image viewer turns the option on; the diagram viewer and the
wheel behaviour are unchanged. Tap and the expand button still open the
viewer with the usual animation.

The research note suggested `touch-action: pan-x pan-y` on the figure.
It is deliberately not used: in Mobile Safari on the iOS 27.2 simulator
it stopped a one-finger drag that starts on the image from scrolling the
note, and preventing the events is enough to hold page zoom at 1.00x.

Signed-off-by: Matt Toohey <contact@matttoohey.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ages

Follow-up to the pinch-to-open and pinch-to-close work, applying its
review and three behaviour changes.

Review findings:

- A cancelled touch sequence no longer closes the viewer. d3-zoom sends
  touchcancel down the same path as touchend, so a system interruption
  while the picture was below the close ratio closed it. The zoom
  controller now reports onRelease(false) for a touchcancel, matching
  the opening recogniser.

- The opening recogniser can no longer be left holding a gesture. Touch
  events stay with the element a finger landed on, so the end of a
  sequence never reached the container when one finger was outside it,
  or when the touched element was removed mid-gesture; the next
  one-finger drag then had every move prevented and did not scroll.
  Once two fingers are down the recogniser now follows the sequence on
  the touch targets themselves as well, and a touchstart that carries
  none of the fingers it was tracking starts afresh.

- A pinch close to an inline image that is only partly in view no
  longer lands the picture on top of whatever covers the rest (the note
  header, the chat composer). visibleImagePlace reports the area the
  image shows through, and the viewer closes a clip in to it while the
  picture settles.

Behaviour:

- A pinch-in that starts zoomed in meets a rubber band at the fitted
  size instead of a hard stop: the picture gives up to a fifth of the
  fit, with growing resistance, and springs back on release. It still
  never closes within that gesture. d3-zoom keeps the scale the fingers
  ask for; only the transform reported to the viewer resists.

- An opening pinch carried past the fitted size stays at the scale
  under the fingers on release, as a zoom in the open viewer would,
  instead of snapping back to the fit. The new settleTransform on the
  controller brings the placement within the scale limit (about the
  fingers) and the content constraint. Released short of the fit it
  still goes on to the fit.

Tests: a MediaViewerModal component test covers where the picture goes
when a pinch ends (back to the image, clipped, shrink and fade with
nowhere to return to, cancelled, and the opening outcomes), alongside
unit tests for the rubber band, touchcancel, settleTransform and the
recogniser's stuck states.

Signed-off-by: Matt Toohey <contact@matttoohey.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T04:47:43.531895Z 9553fe3 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@matt2e
matt2e merged commit b627f2d into main Nov 20, 2026
8 checks passed
@matt2e
matt2e deleted the multi-touch-to-open-close-images branch November 20, 2026 05:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant