Skip to content

fix(mobile): preserve streaming drafts and stabilize image zoom - #663

Merged
huichen merged 1 commit into
mainfrom
claude/mobile-zoom-draft
Sep 16, 2026
Merged

huichen merged 1 commit into
mainfrom
claude/mobile-zoom-draft

Conversation

@huichen

@huichen huichen commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Allow drafting the next message during streaming while blocking send-button and keyboard submission until the reply finishes.
  • Preserve existing draft storage and the stop control; do not auto-submit drafts.
  • Claim two-finger image gestures immediately, anchor zoom at the pinch midpoint, and rebase pinch/pan transitions without jumps. Reset previews when switching images or resizing.
  • Add regression coverage for draft retention, submission guards, repeated pinches, focal-point tracking, finger transitions, and resize reset.

Validation

  • Mobile TypeScript check passed.
  • Mobile ESLint passed.
  • Mobile Jest: 97 suites / 1,370 tests passed.
  • Native device gesture validation not performed.

Only the five files for this fix are included; unrelated local streaming-performance work is excluded.

@huichen
huichen enabled auto-merge (squash) September 16, 2026 09:51
@huichen
huichen merged commit be0b5a4 into main Sep 16, 2026
12 checks passed
@huichen
huichen deleted the claude/mobile-zoom-draft branch September 16, 2026 09:53
huichen added a commit that referenced this pull request Sep 20, 2026
… it on the picture (#728)

* fix(mobile): make the image preview's zoom reach the picture on device

The preview's pinch was reported as doing nothing on a phone. The gesture was
only claimed once a SECOND finger negotiated the responder:

    onStartShouldSetPanResponder: event => event.nativeEvent.touches.length === 2

so ownership depended on how the container handled the initial touch, and #663's
own note said native delivery had never been validated on a device. Claim the
surface on the first finger instead (capture phase): the picture has no other
gesture to protect, and a press that does not travel is only read as a
double-tap candidate. That is also how the established RN zoom components do it.

While in here:

- `onLayout` measured through `event.currentTarget`, which is not a measurable
  instance on every renderer — on the web harness it threw
  "Cannot read properties of undefined (reading 'measureInWindow')" on every
  open, leaving the frame's screen origin at 0 and the zoom anchor wrong.
  Measure through a ref, as RN documents.
- Add double-tap zoom: one finger in, one finger back to fit, anchored on the
  tap. Pinch is not available to every user (assistive settings) and not every
  device manifests it, so the surface must not depend on it alone. The focal
  math is shared with the pinch through one `zoomTo` helper.
- The controller now exposes `state()`, because a double-tap's result is
  delivered by a spring and the animated value is not observable in tests.

Verification: unit tests cover the native contract (anchor, bounds, pan clamps,
finger transitions, double-tap window/slop, and that a two-finger press is never
a tap). The new `mobile/image-zoom` scenario drives the real preview with
dispatched TouchEvents and asserts the scale RN applied, so the capture run
fails if zoom stops working; docs note that a harness capture can prove "the
scale changed" but not the focal offset, because the browser's measureInWindow
is in page space while touches are dispatched in viewport space.

* fix(mobile): stop the inline-image load callback from throwing without a size

`LoadedImage`'s `onLoad` destructured `nativeEvent.source` directly. That size
only exists on renderers that decode the image natively: react-native-web reports
no `source`, so every inline image threw inside the load callback there
("Cannot read properties of undefined (reading 'width')"). It looked harmless
because `onImageLoad` failures do not unmount the picture, but it is a real
uncaught error on that renderer and it made the screenshot harness console
unreadable for genuine problems.

Read the size defensively and keep the existing 1.5 default when it is absent. The
new test fails against the old code and covers the three shapes the callback can
arrive in: a real size, an empty `nativeEvent`, and no event at all.

* fix(mobile): anchor the preview's zoom on the picture, not on a measured origin

The zoom resolved every focal point against the view's window origin, which is
measured once per layout. A sheet that slides in lays out while it is still below
the viewport: the captured origin was 904 while the surface's real top was 60, and
nothing re-measures afterwards. Every pinch then translated the picture by
`offset × (scale − 1)` — most of a screen — so the zoom dragged the image out of
view instead of growing it under the fingers. The harness showed it plainly: the
pinch state was a uniform, empty frame.

Anchor on the touches' coordinates relative to the surface (`locationX`/
`locationY`), which each event recomputes, so no origin can go stale — and the
`measureInWindow` machinery (and the ref it needed) goes away with it. The pan and
the double-tap anchor use the same relative space.

The scenario now asserts what the user sees: a pinch centred on the picture must
leave the translate near zero (it fails on the previous behaviour), alongside the
scale assertion. Unit tests move to the relative contract and add that centred
case; six of them fail against the previous implementation.

Note for the harness: the mobile workspace's jest tree is unusable right after
`serve-mobile` installs its web dependencies (missing @react-native/jest-preset);
`npm ci` restores it.
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