Skip to content

Double tap to zoom a gesture area, glide after a drag, and hand drags it can't use to its parent - #220

Open
simonhamp wants to merge 3 commits into
mainfrom
feat/gesture-area-double-tap-zoom
Open

simonhamp wants to merge 3 commits into
mainfrom
feat/gesture-area-double-tap-zoom

Conversation

@simonhamp

@simonhamp simonhamp commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Renderers for NativePHP/mobile-air#716: double tap to zoom on native:gesture-area, and a new rule for when a bounded area takes a drag.

In Blade the double tap is @doubleTap.zoom="2" and the scale is :zoom (with zoom-min, zoom-max and @zoomEnd). mobile-air turns those into the props read here: double-tap-zoom, and the same pinch-* keys as before.

A bounded area only takes drags it can use

A bounded area with its pans bound used to take every one-finger drag. So a photo pager had to unbind the pans at whole size (or the pager couldn't page and the drag to close never closed) and rebind them from PHP after each zoom, and the first version of this PR added zoom-pan-x / zoom-pan-y so the zoom could still aim.

Now the area takes a drag only while the zoomed content has more than 2pt of room to move the way the finger is going, judged from the live zoom when the drag would start. At whole size the drag goes to whatever is around the area: a pager pages, a drag to close closes, a scroll view scrolls. Zoomed in, the photo pans and they stay still. A zoomed photo at its right edge leaves a swipe left to the pager. It keeps drags from a gesture area's pan around it, though, so a drag to close only works at whole size and panning a zoomed photo up to its edge doesn't start closing the viewer. A zoom that ends a hair past whole size (under about 1.01x on a phone) still counts as whole size. zoom-pan-* is gone; the pinch and the double tap aim with the bound pans.

  • iOS: bounded areas use a UIKit pan that decides in gestureRecognizerShouldBegin. Scroll view pans, an enclosing area's one-axis pan and the iOS 26 swipe back wait for it. It runs alongside the pinch and the double tap, and picks the pans that wait out by what they are, since SwiftUI can host nested areas on one UIView.
  • Android: the drag judges room once, at touch slop, and otherwise leaves the drag unconsumed for the parent. Once a parent has it, only a second finger landing (a pinch) takes it back. Compose's slop helper re-judged fast drags on every event and could grab a page swipe back mid-flight, so this uses its own small loop.

A drag past the edge pulls the pager on

When zoomed content reaches its edge part way through a drag, the rest of the drag moves the pager or scroll view around the area, so the next photo slides in the way it does in Photos. Going back the other way gives the pager its page back before the photo pans again. On release the pager goes on to the next page past halfway or with a flick that way, and back otherwise. With nothing around to take it, the content stretches past the edge and springs back as before.

  • iOS: the area's pan finds the innermost scroll view around it on that axis (the scroll views whose pans waited on it, and its superviews) and moves its offset itself, at most a page from where it was for a paging one. It settles a paging scroll view with setContentOffset(_:animated:).
  • Android: nested scrolling. The drag dispatches what's past the edge as post-scroll and only offers back, as pre-scroll, what it handed out. Compose's pager settles a handed-off drag by how far the finger went since it landed, most of which panned the photo, so a slow drag a quarter of the way on paged. The pager's page connection (PagerHandOff in PagerRenderer) now settles that case itself by the pager's own position and the flick.

Inertia

Let go of a bounded drag and the content glides on at the finger's speed, slowing at UIScrollView's normal rate, and bounces off an edge it reaches with a critically damped spring. Both platforms step the same exact solution per frame, so the frame rate doesn't change where it lands. A finger held still for 40ms before it lifts doesn't glide: neither platform sends moves while a finger is still, so both trackers would otherwise report the speed it last moved at. on_drag_end fires on release with where the content will come to rest. A finger landing on gliding content stops it.

Clipping

A bounded area clips its content, so a zoomed portrait photo no longer draws over the bottom of Android's close row, or onto the next page while paging.

Double tap to zoom

A double tap at whole size zooms to double-tap-zoom, bringing the tapped point to the middle as far as bounded lets the pan go. A double tap past 1 goes back to 1 and the middle. It animates (0.35s, ease out), and on_pinch_end reports the new scale once it lands. iOS uses SwiftUI's SpatialTapGesture(count: 2) as a simultaneous gesture. Android has its own small detector that consumes nothing.

While that zoom is running, room is judged at the smaller of the live scale and where the zoom is heading. So a swipe during a zoom-out pages and the zoom still finishes. A swipe in the first frames of a zoom-in pages; once the zoom has real room, the drag pans and stops it where it is.

Fixed on the way, all found on devices

  • iOS: the finger left after a pinch couldn't pan until both fingers lifted. That's older than this PR; Android already handled it.
  • iOS: picking up content a pinch had left past an edge jumped it inward.
  • Android: the first pinch after a double tap started from the scale before the double tap.
  • Both: a swipe during the double tap's zoom-out stopped it part way and left the photo zoomed.

Behaviour changes worth knowing

  • A bounded area with no pan bound (only on_drag_end) no longer takes drags.
  • A cancelled bounded drag now springs back and reports on_drag_end, as the one-axis pan already did.
  • A zoomed bounded area with a gesture area's pan around it on an axis it fits on (a landscape photo's height, say) keeps vertical drags from that pan. Before, it did the same, since it took every drag while zoomed.

Testing

Android: new GestureAreaBoundedPanTest, 24 cases, nine of them for the hand-off, the glide, the held-still release and the drag to close at a zoomed edge. The pager and the drag to close are stand-ins (HorizontalPager and detectVerticalDragGestures), because the module's NodeView can't hold a gesture area. The whole module passes (90). The cases for each fix fail without it.

iOS: swiftc -typecheck -wmo against mobile-air's NativeRender gives the same errors as main (core types outside that folder), none in this file, with a canary to prove the file was compiled.

Second round (glide, hand-off, clipping), same setup. On iOS, measured from screenshots: an 80pt flick glides the photo exactly to its edge, the same flick held still for 300ms stops where the finger did, a slow drag past the edge pulls the next image in (on video) and goes back on a held release short of halfway, a fast one pages, a drag out and back leaves the pager on its page and the photo where it started, a swipe at the edge pages, and a drag down on a zoomed photo stays with it while at whole size it closes. On Android the same, plus: the zoomed portrait photo stays below the close row, and at the last image a drag past the edge stretches and springs back. A fast drag past the edge was only checked on Android in Robolectric.

First round: the devnull image viewer (NativePHP/dev-null-app#175) with this branch and mobile-air#716 in vendor, against a local API, on an iOS 27.0 iPhone 18 Pro simulator and an Android 35 emulator. Real double taps and pinches on both: the iOS Simulator tool's two-finger paths, and injected MotionEvents on Android. Checked:

  • paging and drag to close at whole size, trailing the finger by touch slop with no jump
  • panning without paging or closing when zoomed, and the rubber band past an edge
  • 1.007x still pages, 1.010x pans
  • the double tap aims within 2px of the middle and goes back to 1x
  • a swipe or drag to close during the zoom-out, and a fast flick near its end
  • a pinch after a double tap carries on from 2x
  • a second finger landing while paging or closing becomes a pinch, and the pager and drag to close ease back
  • the finger left after a pinch drags on 1:1

Not checked on iOS: lifting the first finger of a pinch and catching a spring back mid-flight, which the simulator tools can't do cleanly. Worth a try on a phone before merging.

🤖 Generated with Claude Code

A gesture area with double-tap-zoom zooms its pinch to that scale on a
double tap, bringing the tapped point to the middle as far as bounded
lets the pan go. A double tap on content that's already zoomed goes back
to 1. Both animate like the spring back, and on_pinch_end reports the
new scale once the zoom lands, so a screen that tracks the zoom from its
pinches hears this one too.

Aiming a zoom moves the pan. A photo pager only binds pan-x and pan-y
once the picture is zoomed, because a bound pan takes every drag and the
pager would stop paging. zoom-pan-x and zoom-pan-y give the pinch and the
double tap those values without taking any drags, so a double tap at
whole size can aim, and a first pinch now zooms around the fingers too.

The double tap cancels and consumes nothing, so pinches, pans, pagers and
an outer drag to close keep working. On iOS a tap ends a zero-length drag
when the pan is bound, which used to restart the spring back; it now
leaves a settle alone when nothing is out of place, or it would stop the
zoom the second tap just started.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
simonhamp added a commit to NativePHP/dev-null-app that referenced this pull request Nov 18, 2026
A double tap on an image at its whole size zooms to half the most it
zooms (twice), with the tapped point brought to the middle as far as the
picture's bounds allow. A double tap on a zoomed image goes back to its
whole size. Both animate on the phone and report through the same
@pinchEnd as a pinch, so the pans bind and let go as before.

The viewer no longer slides up. The black fades in over the screen while
the tapped picture grows out of its thumbnail into place, and closing
runs that backwards. After paging, it shrinks into the thumbnail of the
image it's showing. With no thumbnail on screen it only fades. Each
commit image now has a ref of its own (thumb-{id}) for this, beside the
pressable's, and showImagesInViewer() takes those refs.

Every page also hands its pans to the zoom as zoom-pan, which takes no
drags. That's what lets a double tap at whole size aim, and it means the
first pinch now zooms around the fingers rather than the middle.

This needs NativePHP/mobile-ui#220 and #221 and NativePHP/mobile-air#716.
Until they're in, mobile-ui ignores the new attributes: the viewer slides
up as before and a double tap does nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@simonhamp
simonhamp marked this pull request as ready for review November 19, 2026 22:23
…ound it

A bounded area with its pans bound used to take every one-finger drag, so a
photo pager had to unbind the pans at whole size and rebind them from PHP after
each zoom, and #220 added zoom-pan-x/y so the zoom could still aim. Now the
renderer decides: the area takes a drag only while the zoomed content has more
than 2pt of room on a bound axis. At whole size the drag goes to the pager, the
drag to close or the scroll view around it. Zoomed in, the photo pans and they
stay still. zoom-pan-x/y are gone; the pinch and the double tap move the bound
pans.

iOS: bounded areas use a UIKit pan that decides in gestureRecognizerShouldBegin
from the live zoom. Scroll view pans, an enclosing area's one-axis pan and the
iOS 26 swipe back wait for it.

Android: the bounded drag judges room once at touch slop and otherwise leaves
the drag unconsumed. Once a parent has it, only a second finger (a pinch) takes
it back. Compose's slop helper re-judged fast drags on every event and could
grab a page swipe back mid-flight, so this uses its own small loop.

Fixed on the way, all found on devices:
- iOS: the finger left after a pinch couldn't pan until both lifted.
- iOS: picking up content a pinch left past an edge jumped it inward.
- Android: the first pinch after a double tap started from the old scale.
- Both: a swipe during a double tap's zoom-out stopped the zoom part way and
  left the photo zoomed. While that zoom runs, room is judged at the smaller
  of the live scale and where the zoom is heading.

GestureAreaBoundedPanTest covers paging and closing at whole size, panning
when zoomed, 1.01x still paging, the zoom-out swipe, a pinch after a double
tap and a second finger landing mid-page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
simonhamp added a commit to NativePHP/mobile-air that referenced this pull request Nov 20, 2026
The renderers (NativePHP/mobile-ui#220) now give a bounded area a one-finger
drag only while its zoomed content has room to move, so a photo pager can keep
pan-x/pan-y bound all the time. The pinch and @doubleTap.zoom aim with those
pans, which makes zoom-pan-x/y and switching the pans from PHP unnecessary.
The docblock says how drags are taken and the pager example binds the pans
directly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
simonhamp added a commit to NativePHP/dev-null-app that referenced this pull request Nov 20, 2026
With NativePHP/mobile-ui#220 and NativePHP/mobile-air#716, a bounded gesture
area only takes a one-finger drag while its zoomed image has room to move, so
at whole size the pager pages and the drag to close closes with the pans
bound. Each page now binds its pans all the time. $viewerZoomed,
viewerZoomEnded(), ImageViewer::ZoomedPast, @pinchEnd, zoom-pan and the
swapped close area are gone.

This needs those two PRs: without them a bound pan takes every drag, so the
pager wouldn't page and the drag to close wouldn't close.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@simonhamp simonhamp changed the title Zoom a gesture area on a double tap, aimed at the tapped point Double tap to zoom a gesture area, and let a bounded area leave drags it can't use to its parent Nov 20, 2026
A bounded drag now carries on at the finger's speed when it lifts,
slowing to a stop and bouncing off an edge it reaches, the way a scroll
view does. A finger held still before it lifts doesn't glide. on_drag_end
reports where the content will come to rest.

Zoomed content that reaches its edge part way through a drag hands the
rest of the drag to the pager or scroll view around it, so the next
photo slides in as Photos does, and a flick from there pages. On Android
this goes through nested scrolling, and the pager settles a handed-off
drag by its own position and the flick, since Compose's would decide by
how far the finger went. On iOS the drag moves the enclosing scroll view
itself.

Whether a drag is the area's now depends on its direction too: a zoomed
photo at its right edge leaves a swipe left to the pager. Zoomed content
keeps drags from a gesture area's pan around it though, so a drag to
close only works at whole size.

A bounded area clips its content, so a zoomed photo no longer draws over
Android's close row or onto the next page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
simonhamp added a commit to NativePHP/mobile-air that referenced this pull request Nov 20, 2026
Renderers in NativePHP/mobile-ui#220 now let zoomed content glide after a
drag, hand a drag past its edge to the pager around it, and clip the
content to the area. A drag to close only gets drags at whole size.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
simonhamp added a commit to NativePHP/dev-null-app that referenced this pull request Nov 20, 2026
…e pager

With NativePHP/mobile-ui#220's latest commit, a drag past a zoomed
image's edge pulls the pager on to the next image, a drag that way at
the edge pages, and a drag let go glides on. The drag to close still
only gets drags at whole size.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@simonhamp simonhamp changed the title Double tap to zoom a gesture area, and let a bounded area leave drags it can't use to its parent Double tap to zoom a gesture area, glide after a drag, and hand drags it can't use to its parent Nov 20, 2026
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