Repository navigation
Harden gesture recognizer dispatch API contracts - #37671
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8a985776-9569-4caf-917c-64051900e5c6
…gesture-dispatch-apis
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8a985776-9569-4caf-917c-64051900e5c6
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 37671Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 37671" |
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
Pull request overview
This PR tightens the public gesture-recognizer dispatch contracts introduced in #37420 by enforcing null-argument validation for sender/args at the API boundary, aligning nullability annotations across TFMs, and ensuring active-drag state is reset when a new drag starts.
Changes:
- Add
ArgumentNullExceptionguards forTapGestureRecognizer.SendTappedand allPointerGestureRecognizer.SendPointer*dispatch methods, plus new unit tests asserting the contract. - Make
DropGestureRecognizer.SendDropvalidateargssynchronously and update PublicAPI entries to reflect non-nullable args/return. - Clear stale drag state when starting a new drag operation (including cancel/handled replacement scenarios), with targeted unit test coverage.
Show a summary per file
| File | Description |
|---|---|
| src/Controls/tests/Core.UnitTests/Gestures/TapGestureRecognizerTests.cs | Adds coverage for null sender contract on SendTapped. |
| src/Controls/tests/Core.UnitTests/Gestures/PointerGestureRecognizerTests.cs | Adds coverage for null sender contract on all pointer dispatch methods. |
| src/Controls/tests/Core.UnitTests/Gestures/DropGestureRecognizerTests.cs | Updates test to assert synchronous null-arg validation for SendDrop. |
| src/Controls/tests/Core.UnitTests/Gestures/DragGestureRecognizerTests.cs | Adds coverage for clearing active-drag state when a replacement drag is canceled. |
| src/Controls/src/Core/TapGestureRecognizer.cs | Adds null validation + documents exception/intent for SendTapped. |
| src/Controls/src/Core/PointerGestureRecognizer.cs | Adds null validation + documents exception/intent for pointer dispatch methods. |
| src/Controls/src/Core/DragAndDrop/DropGestureRecognizer.cs | Refactors SendDrop to validate synchronously and updates nullability context for public signatures. |
| src/Controls/src/Core/DragAndDrop/DragGestureRecognizer.cs | Resets active-drag state at the start of SendDragStarting. |
| src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt | Updates nullability annotations for SendDragLeave/SendDrop. |
| src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt | Updates nullability annotations for SendDragLeave/SendDrop. |
| src/Controls/src/Core/PublicAPI/net-windows/PublicAPI.Unshipped.txt | Updates nullability annotations for SendDragLeave/SendDrop. |
| src/Controls/src/Core/PublicAPI/net-tizen/PublicAPI.Unshipped.txt | Updates nullability annotations for SendDragLeave/SendDrop. |
| src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt | Updates nullability annotations for SendDragLeave/SendDrop. |
| src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt | Updates nullability annotations for SendDragLeave/SendDrop. |
| src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt | Updates nullability annotations for SendDragLeave/SendDrop. |
Review details
Suppressed comments (2)
src/Controls/src/Core/DragAndDrop/DropGestureRecognizer.cs:139
- The PR description mentions documenting the infrastructure-only intent consistently across the public dispatch hooks, but these DropGestureRecognizer dispatch methods still lack the same infrastructure remark used on other Send* methods (e.g., TapGestureRecognizer.SendTapped, PointerGestureRecognizer.SendPointerEntered). Consider adding the remark here so the public contract documentation is consistent.
This issue also appears on line 152 of the same file.
/// <summary>
/// Executes the associated command and raises the <see cref="DragLeave"/> event.
/// </summary>
/// <param name="args">The event arguments that describe the drag operation.</param>
/// <exception cref="ArgumentNullException"><paramref name="args"/> is <see langword="null"/>.</exception>
src/Controls/src/Core/DragAndDrop/DropGestureRecognizer.cs:154
- DropGestureRecognizer.SendDrop is a public dispatch hook; to align with the other public Send* methods that now document their infrastructure-only usage, consider adding the same infrastructure remark to this XML doc as well.
/// <param name="args">The event arguments that describe the drop operation.</param>
/// <returns>A task that completes when event dispatch and any default drop processing are complete.</returns>
/// <exception cref="ArgumentNullException"><paramref name="args"/> is <see langword="null"/>.</exception>
- Files reviewed: 15/15 changed files
- Comments generated: 0
- Review effort level: Lite
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8a985776-9569-4caf-917c-64051900e5c6
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8a985776-9569-4caf-917c-64051900e5c6
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8a985776-9569-4caf-917c-64051900e5c6
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.
| dragRec.SendDropCompleted(new DropCompletedEventArgs()); | ||
| dragRec.SendDropCompleted(new DropCompletedEventArgs()); | ||
|
|
||
| Assert.Equal(1, counter); |
There was a problem hiding this comment.
🔍 AI-Generated Review (multi-model)
[minor] Regression Prevention and Test Coverage — This test is non-discriminating: it passes identically with and without the _isDragActive = false; line added in DragGestureRecognizer.SendDragStarting. Trace the uncancelled sequence without the fix: start #1 sets _isDragActive = true; start #2 does not reset but still falls through to _isDragActive = true; SendDropCompleted #1 sees true, increments to 1 and sets false; #2 early-returns. Result is 1 either way, so this test cannot fail if the fix is reverted. Only CanceledDragStartingClearsPreviousActiveDrag actually exercises the changed line. To make this case meaningful, assert observable per-operation identity rather than a raw count — e.g. capture the DropCompletedEventArgs instance/args passed to the handler and assert the completion corresponds to the second (replacement) operation, or assert that a canceled replacement followed by an uncancelled one restores dispatch. As written it adds runtime without adding regression protection.
MauiBot
left a comment
There was a problem hiding this comment.
AI Review Summary
@jfversluis — new AI review results are available based on commit
50cd175.
🗂️ Review Sessions — click to expand
🚦 Gate — Test Before & After Fix
Gate Result: ✅ PASSED
Platform: ANDROID · Base: net11.0 · Merge base: 6202a720
| Test | Without Fix (expect FAIL) | With Fix (expect PASS) |
|---|---|---|
🧪 DragGestureRecognizerTests DragGestureRecognizerTests |
✅ FAIL — 80s | ✅ PASS — 63s |
🧪 DropGestureRecognizerTests DropGestureRecognizerTests |
✅ FAIL — 23s | ✅ PASS — 20s |
🧪 PointerGestureRecognizerTests PointerGestureRecognizerTests |
✅ FAIL — 22s | ✅ PASS — 21s |
🧪 TapGestureRecognizerTests TapGestureRecognizerTests |
✅ FAIL — 24s | ✅ PASS — 20s |
🔴 Without fix — 🧪 DragGestureRecognizerTests: FAIL ✅ · 80s
Error-relevant lines (filtered from the build log):
at Microsoft.Maui.Controls.Core.UnitTests.DragGestureRecognizerTests.CanceledDragStartingClearsPreviousActiveDrag() in /_/src/Controls/tests/Core.UnitTests/Gestures/DragGestureRecognizerTests.cs:line 159
at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
🟢 With fix — 🧪 DragGestureRecognizerTests: PASS ✅ · 63s
(no coded error found; showing last 1200 chars)
kageCorrectlyExtractedFromCompatibleElement(fieldType: typeof(Microsoft.Maui.Controls.Switch), result: "True") [1 ms]
Passed TextPackageCorrectlyExtractedFromCompatibleElement(fieldType: typeof(Microsoft.Maui.Controls.Entry), result: "EntryTest") [1 ms]
Passed TextPackageCorrectlyExtractedFromCompatibleElement(fieldType: typeof(Microsoft.Maui.Controls.Editor), result: "EditorTest") [< 1 ms]
Passed UserSpecifiedImageIsntOverwritten [13 ms]
Passed PropertySetters [1 ms]
Passed DropCompletedCommandFiresOnce [< 1 ms]
Passed NullDropCompletedArgsDoesNotClearActiveDrag [1 ms]
Passed HandledTest [2 ms]
Passed DragStartingCommandFires [< 1 ms]
Passed CanceledDragStartingClearsPreviousActiveDrag [< 1 ms]
Passed SendDragStartingThrowsForNullElement [< 1 ms]
Passed SendDropCompletedThrowsForNullArgs [< 1 ms]
[xUnit.net 00:00:01.80] Finished: Microsoft.Maui.Controls.Core.UnitTests
Passed UserSpecifiedTextIsntOverwritten [< 1 ms]
Passed DateTextPackageCorrectlyExtractedFromCompatibleElement(fieldType: typeof(Microsoft.Maui.Controls.DatePicker), result: "12/12/2020 12:00:00 AM") [3 ms]
Test Run Successful.
Total tests: 20
Passed: 20
Total time: 2.4589 Seconds
🔴 Without fix — 🧪 DropGestureRecognizerTests: FAIL ✅ · 23s
Error-relevant lines (filtered from the build log):
at Microsoft.Maui.Controls.Core.UnitTests.DropGestureRecognizerTests.SendDropThrowsSynchronouslyForNullArgs() in /_/src/Controls/tests/Core.UnitTests/Gestures/DropGestureRecognizerTests.cs:line 76
at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
🟢 With fix — 🧪 DropGestureRecognizerTests: PASS ✅ · 20s
(no coded error found; showing last 1200 chars)
e: typeof(Microsoft.Maui.Controls.CheckBox), result: "True") [6 ms]
Passed TextPackageCorrectlySetsOnCompatibleTarget(fieldType: typeof(Microsoft.Maui.Controls.Entry), result: "EntryTest") [5 ms]
Passed TextPackageCorrectlySetsOnCompatibleTarget(fieldType: typeof(Microsoft.Maui.Controls.TimePicker), result: "01:00:00") [4 ms]
Passed TextPackageCorrectlySetsOnCompatibleTarget(fieldType: typeof(Microsoft.Maui.Controls.RadioButton), result: "True") [10 ms]
Passed TextPackageCorrectlySetsOnCompatibleTarget(fieldType: typeof(Microsoft.Maui.Controls.Label), result: "LabelTest") [< 1 ms]
Passed TextPackageCorrectlySetsOnCompatibleTarget(fieldType: typeof(Microsoft.Maui.Controls.Editor), result: "EditorTest") [3 ms]
[xUnit.net 00:00:04.62] Finished: Microsoft.Maui.Controls.Core.UnitTests
Passed DateTextPackageCorrectlySetsOnCompatibleTarget(fieldType: typeof(Microsoft.Maui.Controls.DatePicker), result: "12/12/2020 12:00:00 AM") [8 ms]
Passed SendDropThrowsSynchronouslyForNullArgs [< 1 ms]
Passed DropCommandFires [10 ms]
Passed PropertySetters [1 ms]
Passed DragOverCommandFires [< 1 ms]
Test Run Successful.
Total tests: 14
Passed: 14
Total time: 5.7914 Seconds
🔴 Without fix — 🧪 PointerGestureRecognizerTests: FAIL ✅ · 22s
Error-relevant lines (filtered from the build log):
at Microsoft.Maui.Controls.Core.UnitTests.PointerGestureRecognizerTests.SendPointerMethodsThrowForNullSender() in /_/src/Controls/tests/Core.UnitTests/Gestures/PointerGestureRecognizerTests.cs:line 22
at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
🟢 With fix — 🧪 PointerGestureRecognizerTests: PASS ✅ · 21s
(no coded error found; showing last 1200 chars)
mary) [2 ms]
Passed ButtonsPropertyAcceptsValidValues(buttons: Primary | Secondary) [< 1 ms]
Passed ButtonsPropertyAcceptsValidValues(buttons: Secondary) [< 1 ms]
Passed Constructor [< 1 ms]
Passed ButtonsPropertyIntegrationWithGestureHandling [17 ms]
Passed ButtonsPropertyChangedEvent [6 ms]
Passed PointerPressedCommandFires [< 1 ms]
Passed ButtonsPropertyBindingWorksCorrectly [35 ms]
Passed ButtonsPropertyBinding [< 1 ms]
Passed PointerExitedCommandFires [2 ms]
Passed PointerEnteredCommandFires [< 1 ms]
Passed ButtonsPropertyTwoWayBindingWorksCorrectly [4 ms]
[xUnit.net 00:00:04.85] Finished: Microsoft.Maui.Controls.Core.UnitTests
Passed ButtonsPropertyCompatibilityWithExistingCode [11 ms]
Passed ButtonsPropertyFilteringSecondaryOnly [< 1 ms]
Passed ButtonsPropertyDefaultValueMatchesTapGesture [< 1 ms]
Passed ButtonsPropertyDefaultValue [< 1 ms]
Passed ButtonsPropertyChangeTriggersPlatformUpdate [< 1 ms]
Passed ButtonsPropertyConsistencyAcrossGestureTypes [< 1 ms]
Passed PointerOverVsmGestureIsOnlyPresentWithVsm [5 ms]
Passed ButtonsPropertyCanBeSet [< 1 ms]
Test Run Successful.
Total tests: 26
Passed: 26
Total time: 6.0699 Seconds
🔴 Without fix — 🧪 TapGestureRecognizerTests: FAIL ✅ · 24s
Error-relevant lines (filtered from the build log):
at Microsoft.Maui.Controls.Core.UnitTests.TapGestureRecognizerTests.SendTappedThrowsForNullSender() in /_/src/Controls/tests/Core.UnitTests/Gestures/TapGestureRecognizerTests.cs:line 38
at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
🟢 With fix — 🧪 TapGestureRecognizerTests: PASS ✅ · 20s
Determining projects to restore...
All projects are up-to-date for restore.
Test run for /home/vsts/work/1/s/artifacts/bin/Controls.Core.UnitTests/Debug/net11.0/Microsoft.Maui.Controls.Core.UnitTests.dll (.NETCoreApp,Version=v11.0)
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.8.2+699d445a1a (64-bit .NET 11.0.0-rc.1.26379.102)
[xUnit.net 00:00:00.46] Discovering: Microsoft.Maui.Controls.Core.UnitTests
[xUnit.net 00:00:04.63] Discovered: Microsoft.Maui.Controls.Core.UnitTests
[xUnit.net 00:00:04.67] Starting: Microsoft.Maui.Controls.Core.UnitTests
[xUnit.net 00:00:04.91] Finished: Microsoft.Maui.Controls.Core.UnitTests
Passed SendTappedThrowsForNullSender [24 ms]
Passed Constructor [19 ms]
Passed CallbackPassesParameter [9 ms]
Test Run Successful.
Total tests: 3
Passed: 3
Total time: 6.1931 Seconds
📁 Fix files reverted (11 files)
src/Controls/src/Core/DragAndDrop/DragGestureRecognizer.cssrc/Controls/src/Core/DragAndDrop/DropGestureRecognizer.cssrc/Controls/src/Core/PointerGestureRecognizer.cssrc/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txtsrc/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txtsrc/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txtsrc/Controls/src/Core/PublicAPI/net-tizen/PublicAPI.Unshipped.txtsrc/Controls/src/Core/PublicAPI/net-windows/PublicAPI.Unshipped.txtsrc/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txtsrc/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txtsrc/Controls/src/Core/TapGestureRecognizer.cs
📋 Pre-Flight — Context & Validation
PR #37671 Pre-Flight
Context
- Title: Harden gesture recognizer dispatch API contracts
- Base / head:
net11.0/jfversluis-expose-gesture-dispatch-apis - Materialized review commit:
cf35f3a2e41d6b76c054daa02a1450aa7a339b8f - Follow-up to: issue #37338 and merged PR #37420, which exposed gesture dispatch methods for third-party
IGesturePlatformManagerimplementations. - Platform requested for this review: Android. The changed behavior is shared Controls code and is covered by Controls.Core unit tests; no Android device test is required.
- Gate: already passed. Do not rerun gate verification and do not modify
PRAgent/gate/content.md.
Required behavior
TapGestureRecognizer.SendTappedand all fivePointerGestureRecognizer.SendPointer*methods must reject a null sender before dispatching commands or events.DropGestureRecognizer.SendDropmust throwArgumentNullExceptionsynchronously for null input, including when the caller does not await the returned task.DropGestureRecognizer.SendDragLeaveandSendDropmust expose non-nullable public parameter annotations, with a non-nullTaskreturn, across all Controls.Core PublicAPI TFMs.- Starting a replacement drag must invalidate the previously active drag even when the replacement is canceled or handled, so a later stale completion is not dispatched.
- Existing
SendDragOverbehavior remains unchanged.
Current PR approach
- Adds direct
_ = value ?? throw new ArgumentNullException(...)guards to tap and pointer dispatch entry points. - Converts
SendDropfrom anasyncpublic method into a synchronous validating wrapper around a private asyncSendDropCore. - Clears
_isDragActiveat the beginning ofSendDragStarting. - Enables nullable context around the two drop dispatch signatures and updates all seven PublicAPI files.
- Adds targeted tests for the four contracts.
Diff surface
Production files allowed for try-fix modification:
src/Controls/src/Core/DragAndDrop/DragGestureRecognizer.cssrc/Controls/src/Core/DragAndDrop/DropGestureRecognizer.cssrc/Controls/src/Core/PointerGestureRecognizer.cssrc/Controls/src/Core/TapGestureRecognizer.cssrc/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txtsrc/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txtsrc/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txtsrc/Controls/src/Core/PublicAPI/net-tizen/PublicAPI.Unshipped.txtsrc/Controls/src/Core/PublicAPI/net-windows/PublicAPI.Unshipped.txtsrc/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txtsrc/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt
The four changed test files are read-only during try-fix attempts.
Bounded validation
Run only this combined targeted test command:
dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj --filter "FullyQualifiedName~Microsoft.Maui.Controls.Core.UnitTests.DragGestureRecognizerTests|FullyQualifiedName~Microsoft.Maui.Controls.Core.UnitTests.DropGestureRecognizerTests|FullyQualifiedName~Microsoft.Maui.Controls.Core.UnitTests.PointerGestureRecognizerTests|FullyQualifiedName~Microsoft.Maui.Controls.Core.UnitTests.TapGestureRecognizerTests"The gate established that the four classes fail without the PR fix and pass with it. No full suite, gate rerun, UI test, or device test is authorized for STEP 5a.
Repository constraints
- Follow
.github/instructions/public-api.instructions.md; PublicAPI markers must reflect analyzer-derived nullability. - Preserve all pre-existing worktree changes outside the baseline allow-list.
- Use only
pwsh .github/scripts/EstablishBrokenBaseline.ps1and its exact-Restoreform for baseline handling. - Each candidate receives one implementation/test pass and at most one focused correction/retest.
🔬 Code Review — Deep Analysis
Expert Evaluation — PR #37671
Verdict: APPROVE
Confidence: High
Independent Assessment
The submitted fix hardens newly exposed shared gesture-dispatch contracts by rejecting null senders before tap and pointer dispatch, making DropGestureRecognizer.SendDrop validate synchronously, aligning drop API nullability across every Controls.Core PublicAPI TFM, and invalidating stale active-drag state when a replacement drag begins. The implementation is correctly placed in shared Controls code and preserves the existing SendDragOver behavior.
Findings
💡 Test-quality improvement
DragGestureRecognizerTests.ReplacementDragStartingReplacesPreviousActiveDrag is non-discriminating: its final count is 1 both with and without the new _isDragActive = false assignment. The adjacent canceled-replacement test does exercise the production fix, so this is not a blocking coverage gap, but the redundant test should be replaced or strengthened to verify a distinct lifecycle transition.
The raw inline finding is persisted in ../inline-findings.json.
Blast Radius and Failure Probes
- All in-tree Android, iOS, Windows, and Tizen tap/pointer callers guard their view before dispatch, so the new null checks do not break framework callers; they surface invalid third-party implementations of the newly public contract.
- Drag state is per recognizer, and Android/iOS platform flows do not create concurrent drag sessions on one recognizer. Resetting state before replacement dispatch correctly prevents a canceled or handled replacement from leaving the prior drag active.
- Existing awaited platform callers observe no behavior change from splitting
SendDropinto a synchronous validating wrapper and asynchronous core, while fire-and-forget callers now receive the intended immediate exception. - All seven PublicAPI files carry matching non-null annotations.
Evidence
- Trusted Gate: passed; the tests fail without the submitted fix and pass with it.
- Regression-risk artifact: clean, with no overlap or revert candidate.
- Required-check and prior-review GitHub surfaces were unavailable to the expert agent because
ghwas unauthenticated; this does not alter the code finding, and the trusted Gate supplies the required approval gate for this workflow.
Conclusion
The raw PR is functionally sound and ship-ready. The only actionable feedback is a non-blocking improvement to one drag lifecycle test.
🛠️ Try-Fix — Analysis & Comparison
STEP 5a Try-Fix Aggregate
Candidate 1 — Centralized Dispatch and Outcome-Derived Drag State
Result: Blocked before implementation.
The candidate proposed central pointer/tap validation paths, an inline async local function for synchronous SendDrop validation, and assigning _isDragActive from the completed replacement operation's outcome rather than clearing it before event dispatch. This avoids the PR's duplicated guards, separate SendDropCore member, and transient false drag state during re-entrant handlers.
The mandatory baseline command stopped on 43 pre-existing tracked changes under .github/ and eng/. Because no baseline state or modification allow-list was created, no source file was changed and the targeted tests were not run. The exact restore command ran and confirmed there was no baseline state to restore.
Diff: empty. Self-review: 0 findings. Detailed result: ../try-fix-1/content.md. Canonical artifacts: attempt-1/.
Candidate 2 — Contract Tokens and Explicit Drag Lifecycle
Result: Blocked before implementation.
Using candidate 1's recorded result, this candidate avoided its dispatch chokepoints, local async function, and outcome-derived boolean. It instead proposed validated sender tokens with inline dispatch, explicit Idle/Starting/Active drag states, and a continuation-composed single-member SendDrop pipeline.
The mandatory baseline command encountered the same 43 pre-existing tracked changes under .github/ and eng/. No baseline state or allow-list was created, so no source file was changed and the targeted tests were not run. The exact restore command ran successfully and confirmed there was no baseline state to restore.
Diff: empty. Self-review: 0 findings. Detailed result: ../try-fix-2/content.md. Canonical artifacts: attempt-2/.
Aggregate Outcome
Two candidates were generated in the required model order. Both were blocked before implementation by the mandatory baseline script's dirty-worktree guard. Neither candidate was tested, so neither is a validated replacement for the PR. No gate artifact or production file was modified.
🏁 Report — Final Recommendation
⚠️ Final Recommendation: REQUEST CHANGES
Winner: pr-plus-reviewer
The submitted fix is functionally sound and the trusted Gate proves that its contract tests fail without the fix and pass with it. The expert review found no blocking production issue, but it identified one non-discriminating drag replacement test. The single reviewer refinement replaces that test with a handled-replacement scenario that directly covers the otherwise untested Handled state-clearing path, and all 63 targeted gesture tests pass in the required candidate sandbox.
Candidate Comparison
| Rank | Candidate | Implementation | Regression evidence | Assessment |
|---|---|---|---|---|
| 1 | pr-plus-reviewer |
Raw PR plus one focused test correction | Passed: 63/63 targeted tests | Best coverage with no production-code expansion; directly validates both canceled and handled replacement cleanup across the two tests. |
| 2 | pr |
Submitted shared gesture-contract hardening | Passed: trusted Gate; 62 tests reported at PR HEAD | Production fix is correct and mergeable, but ReplacementDragStartingReplacesPreviousActiveDrag produces the same result if the state-reset line is reverted and adds no distinct regression protection. |
| 3 | try-fix-1 |
Proposed centralized validation, local async drop helper, and outcome-derived drag state | Not run: blocked before implementation | No diff or empirical evidence. The proposed final state assignment is plausible, but its changed re-entrancy semantics were never implemented or validated. |
| 4 | try-fix-2 |
Proposed sender tokens, explicit drag lifecycle enum, and continuation-composed drop pipeline | Not run: blocked before implementation | No diff or empirical evidence. It adds substantially more machinery than the localized contract hardening requires and has no test result. |
Expert Review Reconciliation
The reviewer confirmed that all in-tree platform dispatchers guard their views, all seven PublicAPI files agree, the synchronous SendDrop wrapper preserves awaited callers, and the per-recognizer drag reset safely handles canceled or handled replacement starts. Its sole inline finding concerns test discrimination, not runtime correctness.
pr-plus-reviewer resolves that finding without changing the submitted production behavior. Because a candidate other than raw pr wins, the submitted PR should incorporate reviewer.patch before approval.
Validation and Uncertainty
- Trusted Gate: passed; do not rerun.
pr-plus-reviewer: required focused command passed once, 63 passed and 0 failed.try-fix-1andtry-fix-2: blocked by their dirty-baseline guard before any implementation; neither can outrank a passing candidate.- GitHub required-check and prior-review surfaces were unavailable to the expert agent. This report therefore relies on the explicitly trusted Gate and local candidate validation rather than claiming broader CI coverage.
📱 UI Tests — Gestures
Detected UI test categories: Gestures
✅ Deep UI tests — 63 passed, 0 failed across 1 category on platform-pool agent (replaces in-process counts above).
🧪 UI Test Execution Results (deep, platform pool)
| Category | Tests | Snapshot diffs |
|---|---|---|
Gestures |
63/63 ✓ | — |
📎 Download drop-deep-uitests artifact (TRX + snapshot diffs) |
🧭 Next Steps — reviewer changes required
The reviewer-enhanced candidate identified changes that are not yet in the submitted PR.
Why: The submitted production fix is sound, and pr-plus-reviewer preserves it while replacing a non-discriminating drag test with direct coverage of the handled-replacement state reset. Its required targeted validation passed all 63 tests, whereas both try-fix candidates were blocked before implementation and testing.
Address the actionable findings in this review before merging.
…tform backends (#37861) <!-- 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! ### Description of Change External platform backends can already raise tap and pointer gestures, because #37420 / #37671 made `TapGestureRecognizer.SendTapped` and the `PointerGestureRecognizer.Send*` methods public infrastructure APIs. `LongPressGestureRecognizer.SendLongPressing` / `SendLongPressed` were left `internal`, so an out-of-tree backend can detect a long press but has **no supported way to dispatch it**. Concrete blocker: [Redth/Maui.Tizen#9](Redth/Maui.Tizen#9) has to no-op its long press dispatch. This PR promotes both methods to `public` with `[EditorBrowsable(EditorBrowsableState.Never)]` and an `ArgumentNullException` guard on `sender` — the smallest additive surface, patterned exactly on the existing tap/pointer dispatch APIs: ```csharp [EditorBrowsable(EditorBrowsableState.Never)] public void SendLongPressed(View sender, Func<IElement?, Point?>? getPosition = null); [EditorBrowsable(EditorBrowsableState.Never)] public void SendLongPressing(View sender, GestureStatus status, Func<IElement?, Point?>? getPosition = null); ``` A `public ILongPressGestureController` was considered and rejected: no other recognizer added in this wave uses a controller interface, so an interface would be inconsistent with `SendTapped` / `SendPointer*` and would add a second dispatch shape for backend authors to learn. **Nothing else changes.** Command execution (including `CanExecute`), event raising, `GestureStatus` Started/Running/Completed/Canceled transitions, `State` updates, the lazy `getPosition` callback contract, touch-count filtering, cancellation semantics, threading expectations, and every in-box platform call site (iOS/MacCatalyst, Android, Windows, Tizen) are untouched. Widening accessibility has no trimming impact, and `LongPressGestureRecognizer` is entirely unshipped API in `net11.0`, so this is purely additive. ### Reproducing the failure Added `src/Controls/tests/ExternalGestureBackend`, a test-support assembly that is **deliberately excluded** from `Microsoft.Maui.Controls`' `InternalsVisibleTo` list. Before the fix it fails to build: ``` error CS1061: 'LongPressGestureRecognizer' does not contain a definition for 'SendLongPressing' ... error CS1061: 'LongPressGestureRecognizer' does not contain a definition for 'SendLongPressed' ... ``` It now compiles, and its `FakeLongPressGestureBackend` drives the recognizer purely through the public API. Demoting either method back to `internal` breaks that project's build — the contract is enforced by the build, not just by convention. ### Tests New `LongPressGestureRecognizerExternalBackendTests` (Controls.Core.UnitTests) drives the fake external backend: - Full `Started` → `Running` → `Completed` lifecycle, and `LongPressed` ordering *before* `Completed` - `Canceled` raises no `LongPressed` and executes no command - Cancellation when movement exceeds `AllowableMovement` - Command dispatch with `CommandParameter`, and `CanExecute == false` suppression - Sender identity + `getPosition` relative-to-element behavior - `NumberOfTouchesRequired` filtering, and fan-out to every matching recognizer on the view - Reflection guard asserting both methods are `public` and `[EditorBrowsable(Never)]` Also added `SendLongPressed_ThrowsForNullSender` / `SendLongPressing_ThrowsForNullSender` to the existing `LongPressGestureRecognizerTests`, matching `TapGestureRecognizerTests.SendTappedThrowsForNullSender`. **Results:** `Controls.Core.UnitTests` — 6219 passed, 0 failed, 30 skipped (includes the pre-existing `LongPressGestureRecognizerTests` and `LongPressGestureRecognizerPerformanceTests`). `dotnet build src/Controls/src/Core/Controls.Core.csproj -p:PublicApiType=Validate -f net11.0` succeeds with 0 warnings; removing an entry from `PublicAPI.Unshipped.txt` correctly fails with `RS0016`, confirming the analyzer is enforcing the new signatures. No device tests exist for `LongPressGestureRecognizer`; platform behavior stays covered by the existing `LongPressGestureInteraction` UI test, which is unaffected. ### Docs Added `docs/design/GestureDispatchForPlatformBackends.md` for backend authors: the full dispatch table across all recognizers, the shared rules (non-null sender, UI thread, lazy `getPosition` semantics, honoring recognizer configuration), the exact long press call ordering used by each in-box platform, and a complete example backend. ### PublicAPI Added the two entries to all seven `src/Controls/src/Core/PublicAPI/*` TFM folders (`net`, `net-android`, `net-ios`, `net-maccatalyst`, `net-tizen`, `net-windows`, `netstandard`). ### Issues Fixed Unblocks external platform backends (e.g. [Redth/Maui.Tizen#9](Redth/Maui.Tizen#9)) from dispatching long press gestures. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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!
Description of Change
Follow-up to #37420, which exposed gesture recognizer dispatch hooks for third-party
IGesturePlatformManagerimplementations.This change hardens the newly public contract based on post-merge review feedback:
senderinputs before command or event dispatch for tap and all pointer dispatch methods.DropGestureRecognizer.SendDropvalidate synchronously before returning its processing task, so fire-and-forget callers still receive an immediateArgumentNullException.SendDragLeaveandSendDropwith non-nullable parameter and return annotations across every Controls.Core PublicAPI TFM.The existing public
DropGestureRecognizer.SendDragOverbehavior is intentionally unchanged.Validation
net11.0,netstandard2.0,netstandard2.1,net11.0-ios26.5,net11.0-maccatalyst26.5, and both Windows TFMs.Issues Fixed
Follow-up to #37338 and #37420.