-
Notifications
You must be signed in to change notification settings - Fork 2k
[Android] Fix CollectionView selection not triggering when PointerGestureRecognizer is used in ItemTemplate #34627
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
Closed
jpd21122012
wants to merge
12
commits into
dotnet:main
from
jpd21122012:fix/34491-Android-CollectionView-ItemSelectionNotTriggeredWhenPointerGestureRecognizer
Closed
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6f1aa02
[Android] Fix CollectionView selection not triggering with PointerGes…
jpd21122012 5cf444b
[test] Remove Thread.Sleep from Issue34491 and use deterministic UI s…
jpd21122012 4c36477
Merge branch 'main' into fix/34491-Android-CollectionView-ItemSelecti…
jpd21122012 8ff694e
Fix null check for tap and pan detector
jpd21122012 2c1cad8
Improve Issue34491 test reliability and simplify gesture detector usage
jpd21122012 e9e893f
Merge branch 'fix/34491-Android-CollectionView-ItemSelectionNotTrigge…
jpd21122012 fc1393c
Add ClearRecyclerViewTouchListener method
jpd21122012 b1b3c71
Fix missing newline at end of Issue34491.cs
jpd21122012 0b0b96a
Optimize gesture recognizer iteration and fix test formatting
jpd21122012 f1b0656
Fix touch handling by avoiding unnecessary subscription for pointer-o…
jpd21122012 ccce26c
Fix pointer event consumption breaking CollectionView selection on An…
jpd21122012 9b46f92
Fix nullable warning by caching View in SetupGestures
jpd21122012 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| namespace Maui.Controls.Sample.Issues; | ||
|
|
||
| [Issue(IssueTracker.Github, 34491, "CollectionView item selection not triggered when PointerGestureRecognizer is added inside ItemTemplate", PlatformAffected.Android)] | ||
| public class Issue34491 : ContentPage | ||
| { | ||
| public Issue34491() | ||
| { | ||
| var statusLabel = new Label | ||
| { | ||
| Text = "No Selection", | ||
| AutomationId = "StatusLabel", | ||
| Padding = new Thickness(10), | ||
| FontSize = 18 | ||
| }; | ||
|
|
||
| var collectionView = new CollectionView | ||
| { | ||
| AutomationId = "TestCollectionView", | ||
| SelectionMode = SelectionMode.Single, | ||
| ItemsSource = new List<string> { "Item 1", "Item 2", "Item 3" }, | ||
| ItemTemplate = new DataTemplate(() => | ||
| { | ||
| var label = new Label | ||
| { | ||
| Padding = new Thickness(10), | ||
| FontSize = 16 | ||
| }; | ||
| label.SetBinding(Label.TextProperty, "."); | ||
| label.SetBinding(Label.AutomationIdProperty, "."); | ||
|
|
||
| var grid = new Grid | ||
| { | ||
| BackgroundColor = Colors.LightGray, | ||
| Padding = new Thickness(10), | ||
| HeightRequest = 50, | ||
| Children = { label } | ||
| }; | ||
|
|
||
| var pointerGesture = new PointerGestureRecognizer(); | ||
| pointerGesture.PointerEntered += (s, e) => { }; | ||
| pointerGesture.PointerExited += (s, e) => { }; | ||
| grid.GestureRecognizers.Add(pointerGesture); | ||
|
|
||
| return grid; | ||
| }) | ||
| }; | ||
|
|
||
| collectionView.SelectionChanged += (s, e) => | ||
| { | ||
| if (e.CurrentSelection.Count > 0) | ||
| { | ||
| statusLabel.Text = $"Selected: {e.CurrentSelection[0]}"; | ||
| } | ||
| }; | ||
|
|
||
| Content = new VerticalStackLayout | ||
| { | ||
| Padding = new Thickness(10), | ||
| Spacing = 10, | ||
| Children = { statusLabel, collectionView } | ||
| }; | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue34491.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| #if ANDROID | ||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
|
|
||
| public class Issue34491 : _IssuesUITest | ||
| { | ||
| public Issue34491(TestDevice device) : base(device) { } | ||
|
|
||
| public override string Issue => "CollectionView item selection not triggered when PointerGestureRecognizer is added inside ItemTemplate"; | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.CollectionView)] | ||
| public void CollectionViewSelectionWorksWithPointerGestureRecognizer() | ||
| { | ||
| // Wait for CollectionView | ||
| App.WaitForElement("TestCollectionView"); | ||
|
|
||
| // Ensure StatusLabel exists | ||
| App.WaitForElement("StatusLabel"); | ||
|
|
||
| var initialText = App.FindElement("StatusLabel").GetText() ?? string.Empty; | ||
| Assert.That(initialText, Is.EqualTo("No Selection")); | ||
|
|
||
| // Tap item | ||
| App.WaitForElement("Item 1"); | ||
| App.Tap("Item 1"); | ||
|
|
||
| // Retry loop for UI update | ||
| string finalText = string.Empty; | ||
|
|
||
| for (int i = 0; i < 10; i++) | ||
| { | ||
| finalText = App.FindElement("StatusLabel").GetText() ?? string.Empty; | ||
|
|
||
| if (finalText == "Selected: Item 1") | ||
| break; | ||
|
|
||
| Thread.Sleep(500); | ||
| } | ||
|
jpd21122012 marked this conversation as resolved.
Outdated
|
||
|
|
||
| Assert.That(finalText, Is.EqualTo("Selected: Item 1"), | ||
| "SelectionChanged should fire when tapping a CollectionView item that has a PointerGestureRecognizer"); | ||
| } | ||
| } | ||
| #endif | ||
|
jpd21122012 marked this conversation as resolved.
Outdated
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.