Skip to content

[Fix] Image drifting and sliding during simultaneous zoom and pan#572

Open
quaaantumdev wants to merge 1 commit intobluefireteam:mainfrom
quaaantumdev:fix-position-with-scale-and-pan
Open

[Fix] Image drifting and sliding during simultaneous zoom and pan#572
quaaantumdev wants to merge 1 commit intobluefireteam:mainfrom
quaaantumdev:fix-position-with-scale-and-pan

Conversation

@quaaantumdev
Copy link
Copy Markdown

@quaaantumdev quaaantumdev commented Dec 30, 2025

The Issue (User Perspective)

When a user places two fingers on the screen to zoom in (pinch) and moves their hand across the screen at the same time (pan), the image behaves unnaturally. To try this, put two fingers really close together, zoom in using the fingers, then stay on the screen with the two fingers and move them around together. The image will now move below your fingers faster then your fingers are moving.

Instead of "sticking" to the user's fingers, the image appears to slide away or move faster than the fingers themselves. It feels like the image is on a slippery surface; if you zoom in while dragging, the image overshoots the intended position. Additionally, the zoom often feels like it is pulling towards the bottom-right corner rather than staying centered between the two fingers.

Expected Behavior: The specific point of the image underneath the user's fingers should remain exactly under their fingers throughout the entire gesture, regardless of how much they zoom or move.

Technical Detail

The issue stemmed from two logic errors in photo_view_core.dart:

  1. Translation Scaling: The previous logic multiplied the calculated translation offset by the current scale factor. This meant that the more the user zoomed in, the faster the image would pan, causing the "overshoot" effect.
  2. Incorrect Pivot Point: The math previously assumed the transformation origin was always the top-left corner (0,0). However, PhotoView usually defaults to Alignment.center. This mismatch caused the image to drift away from the center of the pinch gesture.

The Fix

The logic in onScaleStart and onScaleUpdate has been updated to use vector math relative to the correct transformOrigin (based on basePosition).

We now calculate the vector from the image's current position to the user's focal point. During the update, we apply the scale delta specifically to that vector and subtract it from the current focal point. This ensures the image stays legally anchored to the touch gesture.

Type of Change

  • Bug fix (non-breaking change which fixes a layout/gesture issue)

Checklist

  • Tested with Alignment.center (default)
  • Verified simultaneous pinch-zoom-pan gestures "stick" to fingers
  • Verified strictScale behavior remains intact

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