[Fix] Image drifting and sliding during simultaneous zoom and pan#572
Open
quaaantumdev wants to merge 1 commit intobluefireteam:mainfrom
Open
[Fix] Image drifting and sliding during simultaneous zoom and pan#572quaaantumdev wants to merge 1 commit intobluefireteam:mainfrom
quaaantumdev wants to merge 1 commit intobluefireteam:mainfrom
Conversation
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.
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:(0,0). However,PhotoViewusually defaults toAlignment.center. This mismatch caused the image to drift away from the center of the pinch gesture.The Fix
The logic in
onScaleStartandonScaleUpdatehas been updated to use vector math relative to the correcttransformOrigin(based onbasePosition).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
Checklist
Alignment.center(default)strictScalebehavior remains intact