improve Android pinch-zoom to maintain focus and center correctly #225
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.
Problem:
On Android, the pinch-to-zoom functionality in the image viewer was zooming from the center instead of the focal point of the pinch. Additionally, when zooming back out, the image would shift abruptly instead of smoothly returning to the center. This caused inconsistent behavior compared to iOS and affected user experience, especially when pinch to zoom on a specific portion of the image.
Solution:
Updated the usePanResponder hook to calculate translation based on the pinch focal point for Android, so zooming happens relative to where the user pinches.
Introduced a threshold (CENTER_THRESHOLD) so the image starts moving toward the center slightly before reaching the initial scale, creating a smooth zoom-out experience.
Ensured that double-tap zoom continues to work correctly by preventing the “snap-to-center” logic from overriding double-tap translations.
Minor cleanup in onRelease to correctly handle tmpScale, tmpTranslate, and currentScale updates.
Impact:
Pinch-to-zoom now works correctly on Android, zooming from the pinch location.
Zoom-out now smoothly centers the image before reaching the initial scale.
Double-tap zoom behavior remains intact and is unaffected by pinch-zoom fixes.
Aligns Android behavior with iOS for a consistent cross-platform experience.
Testing:
Verified pinch-zooming at different focal points.
Verified zoom-out centering behavior.
Verified double-tap zoom on specific portions of the image.
Tested across multiple Android devices to ensure smooth animations.