Repository navigation
[Android] Fix CollectionView item selection not triggered when using PointerGestureRecognizer - #37952
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 37952Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 37952" |
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
This comment has been minimized.
This comment has been minimized.
MauiBot
left a comment
There was a problem hiding this comment.
Expert Review — 5 findings
See inline comments for details.
kubaflo
left a comment
There was a problem hiding this comment.
What's the status of this one? Is it ready for review?
This comment has been minimized.
This comment has been minimized.
MauiBot
left a comment
There was a problem hiding this comment.
Expert Review — 1 findings
See inline comments for details.
|
Note 🔍
|
This comment has been minimized.
This comment has been minimized.
|
Note 🔍
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Note 🔍
|
AI Review Summary
Review status: Evidence-first output is incomplete. Missing or skipped required artifacts cannot support approval; existing Gate and blocking findings remain authoritative. 🗂️ Review Sessions — click to expand🚦 Gate — Test Before & After FixGate Result:
|
This comment has been minimized.
This comment has been minimized.
PR Test Gate
|
…ter gestures (#37952) (#39387) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Description of Change <!-- Enter description of the fix in this section --> Exact backport of [#37952](#37952), merged into `inflight/current` as [`cc8e3495d1e67c9e84964d80671424c4fa9fa39b`](cc8e349). **Target exception:** `inflight/candidate` is explicitly requested for this servicing backport, rather than the template's usual `main` target. Preserves the final merged fix without additional dependencies, tests, or redesign: inspect the Android native view hierarchy for a clickable view, and retain pointer touch ownership only for the initial Down event when no clickable native view owns the sequence. This prevents a PointerGestureRecognizer inside a CollectionView item template from swallowing native item selection. Only `PointerGestureHandler.cs` and `TapAndPanGestureDetector.cs` change: 19 insertions and one deletion. Candidate `e741040bbd9ed84f5ee9fadab207501e4fa0e0a2` has byte-identical pre-fix contents to the source commit's parent in both files. The backport has byte-identical post-fix contents to the merged source. Both deltas have stable patch-id `845193da6780e357ad479b85bedc5560f875f860`. Open and merged Candidate PRs were rechecked by source number, issue number, and mechanism immediately before publishing; no duplicate was found. **Local validation** Host SDK: `11.0.100-preview.6.26359.118`; the Android build targets `net10.0-android36.0`, and managed tests run on `net10.0`. | Command | Result | | --- | --- | | `dotnet build Microsoft.Maui.BuildTasks.slnf --no-restore -p:BuildTaskOnlyBuild=true -p:MauiPlatforms=net10.0-android36.0 -p:IncludePreviousTfms=false -v:minimal` | Initial attempt failed with missing dependency assets (`NETSDK1004`) and .NET Framework 4.7.2 reference assemblies (`MSB3644`); resolved by the following restore and retry. | | `dotnet restore Microsoft.Maui.BuildTasks.slnf -p:BuildTaskOnlyBuild=true -p:MauiPlatforms=net10.0-android36.0 -p:IncludePreviousTfms=false -v:minimal` | Passed. | | `dotnet build Microsoft.Maui.BuildTasks.slnf --no-restore -p:BuildTaskOnlyBuild=true -p:MauiPlatforms=net10.0-android36.0 -p:IncludePreviousTfms=false -v:quiet '-clp:ErrorsOnly;Summary'` | Passed: 3 warnings, 0 errors. | | `dotnet build src/Controls/src/Core/Controls.Core.csproj -f net10.0-android36.0 --no-restore -p:MauiPlatforms=net10.0-android36.0 -p:IncludePreviousTfms=false -v:quiet '-clp:ErrorsOnly;Summary'` | Passed: 0 warnings, 0 errors. | | `dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj -f net10.0 --filter 'FullyQualifiedName~Microsoft.Maui.Controls.Core.UnitTests.PointerGestureRecognizerTests' -p:MauiPlatforms=net10.0-android36.0 -p:IncludePreviousTfms=false -v:quiet '-clp:ErrorsOnly;Summary'` | Passed: 25 tests, 0 failed, 0 skipped. | | `dotnet format whitespace --folder --include src/Controls/src/Core/Platform/Android/PointerGestureHandler.cs src/Controls/src/Core/Platform/Android/TapAndPanGestureDetector.cs --verify-no-changes --verbosity minimal` | Passed; source formatting preserved. | | `git diff --check origin/inflight/candidate...HEAD` | Passed. | | `git diff --exit-code cc8e349 HEAD -- src/Controls/src/Core/Platform/Android/PointerGestureHandler.cs src/Controls/src/Core/Platform/Android/TapAndPanGestureDetector.cs` | Passed; exact merged-source postimages. | | `git diff cc8e349^ cc8e349 \| git patch-id --stable` and `git diff origin/inflight/candidate...HEAD \| git patch-id --stable` | Passed; identical patch-id above. | **Native validation gap:** No emulator/device or manual UI validation was performed. The focused tests cover managed recognizer behavior, not Android native touch dispatch, CollectionView selection, or SelectionChanged. No XCTest, MacCatalyst testing, or foreground/device UI automation was run. CI results have not been evaluated in this task. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #34491 via backport of [#37952](#37952). <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. --> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: dac2dd94-1d58-4022-b496-1ffe726b7768
…PointerGestureRecognizer (#37952) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ### Root cause In PR #34209 , the pointer gesture handling returned true whenever a PointerGestureRecognizer was present (return baseHandled || pointerHandled). This was required to ensure Android continued delivering PointerMoved and PointerReleased events. However, when the gesture was used inside a CollectionView.ItemTemplate, the same handling consumed the touch event before it could reach the CollectionView item. As a result, the CollectionView did not receive its native click event, preventing item selection and SelectionChanged from being triggered. ### Issue Details On Android, adding a PointerGestureRecognizer to a view inside a CollectionView ItemTemplate prevented item selection. Tapping the item raised pointer events, but SelectionChanged did not fire. ### Description of Change <!-- Enter description of the fix in this section --> Updated Android pointer gesture handling in: * PointerGestureHandler now examines the native Android view hierarchy to determine whether the pointer-enabled view is inside a clickable native view. * TapAndPanGestureDetector retains the touch sequence only when no clickable native view owns it. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #34491 ### Regarding test case The test case requires user interaction, so haven't added a test case. <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. --> **Tested the behavior in the following platforms.** - [x] Android - [ ] Windows - [ ] iOS - [ ] Mac | Before | After | |---------|--------| | **Android**<br> <video src="https://github.com/user-attachments/assets/3b880f2b-f76a-4fe8-ac50-03c65e2a10e0" width="300" height="600"> | **Android**<br> <video src="https://github.com/user-attachments/assets/e21172b8-d0fa-48e0-93a9-5c732c7159a9" width="300" height="600"> |
…ter gestures (#37952) (#39387) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Description of Change <!-- Enter description of the fix in this section --> Exact backport of [#37952](#37952), merged into `inflight/current` as [`cc8e3495d1e67c9e84964d80671424c4fa9fa39b`](cc8e349). **Target exception:** `inflight/candidate` is explicitly requested for this servicing backport, rather than the template's usual `main` target. Preserves the final merged fix without additional dependencies, tests, or redesign: inspect the Android native view hierarchy for a clickable view, and retain pointer touch ownership only for the initial Down event when no clickable native view owns the sequence. This prevents a PointerGestureRecognizer inside a CollectionView item template from swallowing native item selection. Only `PointerGestureHandler.cs` and `TapAndPanGestureDetector.cs` change: 19 insertions and one deletion. Candidate `e741040bbd9ed84f5ee9fadab207501e4fa0e0a2` has byte-identical pre-fix contents to the source commit's parent in both files. The backport has byte-identical post-fix contents to the merged source. Both deltas have stable patch-id `845193da6780e357ad479b85bedc5560f875f860`. Open and merged Candidate PRs were rechecked by source number, issue number, and mechanism immediately before publishing; no duplicate was found. **Local validation** Host SDK: `11.0.100-preview.6.26359.118`; the Android build targets `net10.0-android36.0`, and managed tests run on `net10.0`. | Command | Result | | --- | --- | | `dotnet build Microsoft.Maui.BuildTasks.slnf --no-restore -p:BuildTaskOnlyBuild=true -p:MauiPlatforms=net10.0-android36.0 -p:IncludePreviousTfms=false -v:minimal` | Initial attempt failed with missing dependency assets (`NETSDK1004`) and .NET Framework 4.7.2 reference assemblies (`MSB3644`); resolved by the following restore and retry. | | `dotnet restore Microsoft.Maui.BuildTasks.slnf -p:BuildTaskOnlyBuild=true -p:MauiPlatforms=net10.0-android36.0 -p:IncludePreviousTfms=false -v:minimal` | Passed. | | `dotnet build Microsoft.Maui.BuildTasks.slnf --no-restore -p:BuildTaskOnlyBuild=true -p:MauiPlatforms=net10.0-android36.0 -p:IncludePreviousTfms=false -v:quiet '-clp:ErrorsOnly;Summary'` | Passed: 3 warnings, 0 errors. | | `dotnet build src/Controls/src/Core/Controls.Core.csproj -f net10.0-android36.0 --no-restore -p:MauiPlatforms=net10.0-android36.0 -p:IncludePreviousTfms=false -v:quiet '-clp:ErrorsOnly;Summary'` | Passed: 0 warnings, 0 errors. | | `dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj -f net10.0 --filter 'FullyQualifiedName~Microsoft.Maui.Controls.Core.UnitTests.PointerGestureRecognizerTests' -p:MauiPlatforms=net10.0-android36.0 -p:IncludePreviousTfms=false -v:quiet '-clp:ErrorsOnly;Summary'` | Passed: 25 tests, 0 failed, 0 skipped. | | `dotnet format whitespace --folder --include src/Controls/src/Core/Platform/Android/PointerGestureHandler.cs src/Controls/src/Core/Platform/Android/TapAndPanGestureDetector.cs --verify-no-changes --verbosity minimal` | Passed; source formatting preserved. | | `git diff --check origin/inflight/candidate...HEAD` | Passed. | | `git diff --exit-code cc8e349 HEAD -- src/Controls/src/Core/Platform/Android/PointerGestureHandler.cs src/Controls/src/Core/Platform/Android/TapAndPanGestureDetector.cs` | Passed; exact merged-source postimages. | | `git diff cc8e349^ cc8e349 \| git patch-id --stable` and `git diff origin/inflight/candidate...HEAD \| git patch-id --stable` | Passed; identical patch-id above. | **Native validation gap:** No emulator/device or manual UI validation was performed. The focused tests cover managed recognizer behavior, not Android native touch dispatch, CollectionView selection, or SelectionChanged. No XCTest, MacCatalyst testing, or foreground/device UI automation was run. CI results have not been evaluated in this task. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #34491 via backport of [#37952](#37952). <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. --> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: dac2dd94-1d58-4022-b496-1ffe726b7768
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Root cause
In PR #34209 , the pointer gesture handling returned true whenever a PointerGestureRecognizer was present (return baseHandled || pointerHandled). This was required to ensure Android continued delivering PointerMoved and PointerReleased events. However, when the gesture was used inside a CollectionView.ItemTemplate, the same handling consumed the touch event before it could reach the CollectionView item. As a result, the CollectionView did not receive its native click event, preventing item selection and SelectionChanged from being triggered.
Issue Details
On Android, adding a PointerGestureRecognizer to a view inside a CollectionView ItemTemplate prevented item selection. Tapping the item raised pointer events, but SelectionChanged did not fire.
Description of Change
Updated Android pointer gesture handling in:
Issues Fixed
Fixes #34491
Regarding test case
The test case requires user interaction, so haven't added a test case.
Tested the behavior in the following platforms.
Before.mov
After.mov