dotnet / dotnet/maui

PanGestureRecognizer Disables Item Selection In CollectionView

Open
#9,253 4 comments 0 reactions 0 assignees View on GitHub
area-controls-collectionview area-controls-general platform/android s/triaged s/verified t/bug
Dominant language
C#
Stars
23.3k
Forks
2k
Avg merge
1d 15h
Merged PRs (30d)
290

Description

### Description

### Desire
The desire is to be able to pan inside of a `` to move another view across the screen.
To do this, the `` was added inside of the `` so that it could recognize a pan gesture.
Attempts were made to move the gesture recognizer to the parent view of the ``. However, this resulted in the `` not recognizing the pan gesture and simply ignored it.

### What Happens

The `` is selectable until a pan attempt is made. The first pan gesture doesn't seem to be recognized and it takes a little bit of swiping sometimes before the pan will be recognized. At this point clicking off then then panning again will trigger the ``. Once that is triggered, the items in the `` cannot be selected again until the app is closed and restarted.

It has also been noticed that a `` placed in the same area as the PanGesture won't trigger until after the pan has occurred. This makes it seem like where the gesture events are handled are being reset somewhere inside of the ``.

### Reproduction
A simple app to demonstrate the [PanGestureRecognizer Issue](https://github.com/flynn248/CollectionViewTest).

### Example GIF

![DemoOfBug](https://user-images.githubusercontent.com/76095688/183321682-2c62a3dd-3bfd-474c-9313-183c45c67946.gif)

### Steps to Reproduce

### Clone the Repro
For ease of testing, clone this repro that demonstrates the [PanGestureRecognizer Issue](https://github.com/flynn248/CollectionViewTest).
### From Scratch
1. Create a MAUI app.
2. Add a `` that implements the ``. Example shown below.
```xaml



0
1
2
3
4
5












```
3. [Optionally] Add a view that will pan across when panning. This helps to visualize it.
3. Select a few items to verify that selection is working.
4. Pan inside of the ``.
5. Try to select a few items again.

### Expected Outcome
Be able to pan a view across the screen. Then be able to select items in the ``

### Actual Outcome
Able to pan a view across the screen. Unable to select items in the `` anymore.

### Version with bug

6.0.400

### Last version that worked well

Unknown/Other

### Affected platforms

Android, I was *not* able test on other platforms

### Affected platform versions

Android 11

### Did you find any workaround?

The only workaround that I've found thus far is to press a button to remove the `` in the code behind. Then press a button to re-add the ``.

Attempting to clear and then add in the same button event didn't work for me. It had to be separate button events. My guess is that something in the `` needs to update and doing a clear and add right away is to quick for it to be updated properly.

The button presses aren't the important part from what it seems like to me. The important part is to remove the gesture recognizer and then re-add it in a separate event. Removing and re-adding the gesture recognizer using Xaml Hot Reload worked as well in fixing the issue.

### Relevant log output

_No response_

Contributor guide

Open the contributing guide

Research direction

Clone the linked CollectionViewTest reproduction and run the XAML example on Android 11 with .NET MAUI 6.0.400. Start by tracing CollectionView selection and PanGestureRecognizer handling around the reproduced sequence; done means panning still moves the view and CollectionView items remain selectable afterward, with tap gestures working again.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, csharp
Domain
frontend, mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.