Repository navigation
fix(mobile): preserve streaming drafts and stabilize image zoom - #663
Merged
Merged
Conversation
huichen
enabled auto-merge (squash)
September 16, 2026 09:51
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Validation
Only the five files for this fix are included; unrelated local streaming-performance work is excluded.