photo_view
photo_view copied to clipboard
[BUG] in gallery, tap is always panning when zoomed
Describe the bug
Any tap down, tap up or double tap starts to pan when displaying a zoomed image in a PhotoViewGallery
. PhotoViewGalleryPageOptions
callbacks onTapUp
and onTapDown
are not called, and it doesn't cycle through zoom on double tap (though all of this works fine when the image is not zoomed in).
To Reproduce 1 Open the Gallery example 2 Tap on an image to open it 3 Double tap once to zoom 4 Double tap again
What is the current behavior? It starts to pan, even for an unnoticeable amount of pixels.
Expected behavior
It should cycle through zoom, just like it does with a regular PhotoView
(not in a gallery).
Which versions of Flutter/Photo View, and which browser / OS are affected by this issue? Did this work in previous versions of Photo View? Flutter (Channel beta, v1.11.0, on Microsoft Windows [Version 10.0.18363.476], locale en-GB) It used to work with photo_view v0.7.0, the bug appeared in v0.8.0, and it's still here in v0.9.0.
I tried to solve this and came up with a solution. It's not perfect though and has trade off.
The issue is that there are basically 3 competing gesture recognizers:
- the gallery
PageView
drag recognizer, - the
PhotoView
pan/scale recognizer, - the
PhotoView
tap (and double-tap) recognizer.
Solution TLDR:
- wait for the gesture to go beyond slop in the
PhotoView
pan/scale recognizer, - change the
PageView
physics to increasedragStartDistanceMotionThreshold
.
Some explanation...
The current implementation of PhotoView
plays with the pan/scale recognizer, trying to detect whether we are on an edge, to win in the gesture arena and proceed with pan/scale, or let the PageView
recognizer win and slide to another page. This never gives a chance to the tap recognizer.
To let the tap recognizer win, we have to play with the pan/scale recognizer slop
(cf kTouchSlop, kScaleSlop, kPanSlop), which determines how much movement is required before a gesture is understood as a pan/scale. The pan/scale recognizer should not declare victory before the gesture goes beyond the slop threshold.
However this is not enough. The PageView
recognizer, by default, will declare victory if the PhotoView
recognizer waits to reach the slop, so we should make the PageView
recognizer even less reactive by giving it some physics with an appropriate dragStartDistanceMotionThreshold
.
Here's my take: https://github.com/deckerst/photo_view/compare/d8c21a..4399d1
As I said, this is not perfect as it introduces trade-off variables to prioritize the different recognizers, but it works well enough for me.
The problem seems to happen only on Android. On my tests your solution works very well on Android, and causes no colateral effects on iOS.
same issue, but I found that tapdowns are only registered at the bottom corners of the screen
I'm still having this issue right now, tested on android, version ^0.10.3
Double tapping an image will zoom in, however, double tapping again will do nothing in 90% of all cases.
I have the suspision that the second double tap is counted as a drag as the image moves ever so slightly sometimes and as "double tapping" with a mouse on an emulator will actually work every time, since the mouse has no movement between the taps.
I am also having the same issue on version 0.11.1, tested on real android device
I using photo_view package, when I tap once or double tap, it is panning instead. this happens on Samsung phones only. The issue still exist for me. I appreciate any help to fix this.
I am using :
photo_view: ^0.12.0 Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 2.2.3, on macOS 11.2.3 20D91 darwin-arm, locale en-GB) [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3) [✓] Xcode - develop for iOS and macOS [✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome) ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable. [✓] Android Studio (version 4.1) [✓] Connected device (1 available)
@renancaraujo Just applied 508d9b7 in the package directory in my project and works perfectly (No issue with tapping or double tapping or panning). That would be great if you apply these changes to the package itself.
@renancaraujo Just applied 508d9b7 in the package directory in my project and works perfectly (No issue with tapping or double tapping or panning). That would be great if you apply these changes to the package itself.
this make magic 🫡. it make it work on samsung tho. but i doubt it's safe to make changes on the package files 🤔🫠. I wonder if you copy the package file on your own project tree?