Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] in gallery, tap is always panning when zoomed #216

Open
deckerst opened this issue Nov 24, 2019 · 8 comments
Open

[BUG] in gallery, tap is always panning when zoomed #216

deckerst opened this issue Nov 24, 2019 · 8 comments
Labels
bug Something isn't working Gallery P1

Comments

@deckerst
Copy link

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.

@deckerst deckerst added the bug Something isn't working label Nov 24, 2019
@deckerst
Copy link
Author

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 increase dragStartDistanceMotionThreshold.

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.

@eduribas
Copy link

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.

@safety-dispatch
Copy link

same issue, but I found that tapdowns are only registered at the bottom corners of the screen

@clragon
Copy link

clragon commented Jan 26, 2021

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.

eduribas added a commit to eduribas/photo_view that referenced this issue May 14, 2021
@kevsjh
Copy link

kevsjh commented Jun 4, 2021

I am also having the same issue on version 0.11.1, tested on real android device

@ZahraVe
Copy link

ZahraVe commented Aug 3, 2021

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)

@ZahraVe
Copy link

ZahraVe commented Sep 12, 2022

@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.

@spirituelle
Copy link

@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?

jabm111 pushed a commit to jabm111/photo_view that referenced this issue Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Gallery P1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants