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

bugfix: Prevent parent ListView widgets from snatching scrolling gestures #717

Closed

Conversation

ritikmishra
Copy link

Closes #253.

The issue was fixed by using a GestureArenaTeam in conjunction with extra gesture recognizers to ensure that the ScalingGestureRecognizer wins when we would expect it to do so.

@ritikmishra ritikmishra force-pushed the fix-listview-scrolling branch 3 times, most recently from 674d52d to c00da64 Compare August 4, 2020 22:20
@dev-phamquoctrong
Copy link

How to add it into my project? Do you have a example code?

@ritikmishra
Copy link
Author

If you want to use the fork, put the following in your pubspec.yaml

  flutter_map:
    git:
      url: https://github.com/ritikmishra/flutter_map.git
      ref: fix-listview-scrolling

@jakobkuehne
Copy link

Sadly I can't use your git version because of flutter_map_marker_cluster.

Because flutter_map_marker_cluster 0.2.9 depends on flutter_map ^0.10.1+1 and no versions of flutter_map_marker_cluster match >0.2.9 <0.3.0, flutter_map_marker_cluster ^0.2.9 requires flutter_map from hosted.

Or am I doing something wrong? So far, I've never added a package directly from Git. But apart from the possibility to add your great customization via Git, this would be a very important feature and I can't understand why this is still not officially available in flutter_map...

If you want to use the fork, put the following in your pubspec.yaml

  flutter_map:
    git:
      url: https://github.com/ritikmishra/flutter_map.git
      ref: fix-listview-scrolling

Copy link

@romainpurchla romainpurchla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Work for me 👍

@sm2017
Copy link

sm2017 commented Dec 13, 2020

It's worked for me. Can you explain how to it works?

@ritikmishra I'm interested to know that how it works

@johnpryan Please accept the PR

@ritikmishra
Copy link
Author

The mechanism through which Flutter recognizes gestures is called the gesture arena. Different gesture recognizers compete in the arena, and the first recognizer to accept the gesture, or the last recognizer remaining in the arena (i.e the other recognizers rejected the gesture), is responsible for handling it.

Previously, the map was implicitly using 3 gesture recognizers through GestureDetector: ScaleGestureRecognizer (handling panning and zoom), TapGestureRecognizer, and LongPressGestureRecognizer. If the map is inside a widget that scrolls (i.e a ListView), a fourth gesture recognizer will be in the arena: either a HorizontalDragGestureRecognizer or a VerticalDragGestureRecognizer depending on the direction that it scrolls.

The problem was caused by the ScaleGestureRecognizer taking too long to accept the gesture, resulting in the HorizontalDragGestureRecognizer/VerticalDragGestureRecognizer winning in the gesture arena.

The solution was to use a GestureArenaTeam to utilize a new HorizontalDragGestureRecognizer and a new VerticalDragGestureRecognizer to help the original ScaleGestureRecognizer win faster. A GestureArenaTeam has a captain and members -- whenever any gesture recognizer in the team accepts the gesture, the captain is put in charge of handling it. This way, a user can pan the map when it is inside a ListView/other scrollable widget.

@sm2017
Copy link

sm2017 commented Dec 14, 2020

@ritikmishra as the PR is not merged, is there alternative solution , for example wrapping map with another widget?

@ritikmishra
Copy link
Author

I couldn't find a workaround, which is why I made this PR. If you can find some way to stop the ListView from being so greedy in the gesture arena & ensure that the pointer events from gestures that don't go to the ListView do go to the FlutterMap, that should fix the problem.

@gsimko
Copy link

gsimko commented Jan 27, 2021

@johnpryan can you please take a look?

@kengu
Copy link
Contributor

kengu commented Mar 18, 2021

@ritikmishra Can you resolve the conflict and update this PR? I can review it when this is done.

@ritikmishra
Copy link
Author

@kengu i have resolved the conflict

(layer) => _createLayer(layer, options.plugins),
)
],
child: scaleGestureDetector(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand this correctly @ritikmishra, the TeamGestureRecognizer will always ensure that flutter_map takes precedence over ListView scoll? I don't think we can conclude that this is the only behaviour user expect. I think we need to make this behavior configurable, just as it is for scollables in general. I think we should add something similar (or equal) to scrollPhysics to MapOptions constructor.

@johnpryan? What do you think?

@github-actions
Copy link

This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions bot added the Stale label Apr 19, 2021
@BenBitDesign
Copy link

Hi guys

I think @kengu makes a good point to make this configurable.

Is anyone looking into this?

@github-actions github-actions bot removed the Stale label May 21, 2021
@github-actions
Copy link

This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@kengu
Copy link
Contributor

kengu commented Sep 3, 2021

Closing, fixed by #994.

@kengu kengu closed this Sep 3, 2021
@ritikmishra ritikmishra deleted the fix-listview-scrolling branch September 5, 2021 16:22
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.

ListView snatches scroll gestures
8 participants