Repository navigation
feat: Add opt-in press-to-stop-momentum for ManipulationMode panning - #24282
Conversation
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-24282/docs/index.html |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24282/wasm-skia-net9/index.html |
There was a problem hiding this comment.
Pull request overview
Adds an opt-in Uno.UI.Toolkit attached property to make “tap while inertia is coasting” behave like OS scroll surfaces (first tap stops momentum only) for elements that pan via UIElement.ManipulationMode, while explicitly preserving the WinUI-default behavior unless enabled.
Changes:
- Added internal gesture-recognizer state to detect when a pointer down aborts a coasting manipulation, plus an internal UIElement helper to suppress specified gestures for a given pointer.
- Introduced
toolkit:ManipulationExtensions.IsTapToStopInertiaEnabledto suppress tap/hold-related gestures along the pointer route when a tap stops inertia (no-op on WinAppSDK). - Added unit tests, runtime tests, a SamplesApp manual test page, and Toolkit docs for the new opt-in behavior.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/Uno.UI/UI/Xaml/UIElement.Pointers.cs | Adds internal UIElement helpers to surface inertia-abort info and to prevent gesture recognition for a pointer. |
| src/Uno.UI/UI/Input/WinRT/GestureRecognizer.Manipulation.cs | Exposes an IsCoasting state on the internal Manipulation object for inertia detection. |
| src/Uno.UI/UI/Input/WinRT/GestureRecognizer.cs | Tracks whether the last pointer down aborted a coasting manipulation (LastDownStoppedInertia). |
| src/Uno.UI.UnitTests/Windows_UI_Input/Given_GestureRecognizer.cs | Adds unit coverage verifying inertia-abort reporting doesn’t change default tap recognition. |
| src/Uno.UI.Toolkit/ManipulationExtensions.cs | Implements the opt-in attached property and gesture suppression logic along the pointer route. |
| src/Uno.UI.RuntimeTests/Tests/Uno_UI_Toolkit/Given_ManipulationExtensions.cs | Adds runtime tests to pin default behavior and validate the opt-in suppression behavior. |
| src/SamplesApp/SamplesApp.Samples/Windows_UI_Input/GestureRecognizerTests/Manipulation_TapStopsInertia.xaml.cs | Adds a manual sample page code-behind for validating tap-to-stop-inertia behavior. |
| src/SamplesApp/SamplesApp.Samples/Windows_UI_Input/GestureRecognizerTests/Manipulation_TapStopsInertia.xaml | Adds the manual sample UI demonstrating default vs opt-in behavior. |
| doc/articles/Uno.UI.Toolkit.md | Documents the new opt-in, its effect, and platform reach. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24282/wasm-skia-net9/index.html |
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-24282/docs/index.html |
There was a problem hiding this comment.
🔵 Needs a closer look
The new pointer-tracking logic should also handle PointerCaptureLost to avoid stale pending-pointer state and unintended gesture muting in edge cases.
Review details
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
src/Uno.UI.Toolkit/ManipulationExtensions.cs:114
- InertiaStopTracker tracks pointer IDs in _pendingPointers but only cleans up on PointerReleased/PointerCanceled. In Uno, PointerCaptureLost can occur instead of a release/cancel, which would leave stale entries and potentially cause the next reuse of that pointer ID to be muted unexpectedly. Consider handling PointerCaptureLost the same way as release/cancel.
- Files reviewed: 9/9 changed files
- Comments generated: 0 new
- Review effort level: Lite
131769c to
40e19e8
Compare
There was a problem hiding this comment.
🟢 Approval recommended
The change is additive with default behavior preserved and is backed by targeted unit/runtime tests; only a minor nullability contract nit was found.
Review details
- Files reviewed: 9/9 changed files
- Comments generated: 1
- Review effort level: Lite
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24282/wasm-skia-net9/index.html |
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-24282/docs/index.html |
There was a problem hiding this comment.
🔵 Needs a closer look
A verified edge case in GestureRecognizer.ProcessDownEvent can leave inertia coasting while reporting LastDownStoppedInertia, which can break the opt-in’s correctness unless addressed.
Review details
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
src/Uno.UI/UI/Input/WinRT/GestureRecognizer.cs:101
LastDownStoppedInertiais computed before the gesture is created, but when the down is immediately completed (e.g., double-tap is recognized on Down),ProcessDownEventreturns early and never callsManipulation.AddPointer. In that case the flag can report that the press “stopped inertia” even though the manipulation is still coasting, and Toolkit’s opt-in may try to suppress gestures for a press that didn’t actually abort inertia.
Consider explicitly completing the coasting manipulation in the gesture.IsCompleted early-return path when LastDownStoppedInertia is true, so the flag remains accurate and the down still stops inertia consistently.
- Files reviewed: 9/9 changed files
- Comments generated: 0 new
- Review effort level: Lite
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24282/wasm-skia-net9/index.html |
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-24282/docs/index.html |
|
Tick the box to add this pull request to the merge queue (same as
|
|
@Mergifyio backport release/stable/6.7 |
✅ Backports have been createdDetails
|
…6.7/pr-24282 feat: Add opt-in press-to-stop-momentum for ManipulationMode panning (backport #24282)
GitHub Issue: Tracked internally (customer-reported). No public issue.
PR Type:
✨ Feature
What changed? 🚀
A customer reported that on a tablet, tapping a CommunityToolkit
DataGridwhile it is still decelerating after a fling both stops the momentum and selects the row under the finger, instead of the first tap only halting the scroll.This turned out to be intended WinUI behaviour, not a bug. The
DataGridpans its rows through theManipulationModeof itsDataGridRowsPresenter(runtime-confirmed:TranslateX, TranslateY, TranslateRailsX, TranslateRailsY, TranslateInertia, System), and in WinUI gesture recognition for that path is per-element and independent of an ancestor's inertia:CUIElement(CInteractionManager::m_mapInteractions), so a descendant's tap recognition knows nothing about the panning ancestor's inertia;CInteractionManager::IsManipulationInertiaProcessing()has zero callers, so nothing gates press dispatch while an inertia is running;GestureOutputMapper::OnTapped/OnSecondaryTapped/OnHoldingdropping the message whenIsInteractionStopping() && IsInteractionStopped()— is armed only byElementGestureTracker::Stop(), whose callers are DirectManipulation-steals-the-pointer, capture-changed and focus. Not "a press landed during my own inertia".So WinUI activates the pointed item on that press, and Uno Platform now keeps doing the same by default.
Worth noting the corollary: Uno Platform's own
ScrollVieweris not diverging. Its touch panning goes through the direct-manipulation pipeline, which swallows the press that stops an inertia before it reaches the visual tree — the same thing DirectManipulation does on WinUI. Only theUIElement.ManipulationModepath is affected, which is why the two behave differently today.The gap is nonetheless real on touch-only targets: a browser on a tablet has no mouse, and users expect the OS convention that the first press only stops the momentum. That makes this an enhancement, which must not change default behaviour on any target.
So it ships as an opt-in Toolkit extension:
While enabled, the press that aborts the inertia raises no
Tapped,DoubleTapped,RightTappedorHoldingon the element, its ancestors or its descendants; a tap at rest is unaffected. It is a no-op on Windows.Applied through an implicit
Styleit also reaches panning elements an app cannot address directly — includingDataGrid'sDataGridRowsPresenter, which is the customer's actual case:This does change core code, and the default is unchanged
The Toolkit cannot observe what it needs on its own, so
Uno.UIgains four internals. All of them are purely additive and behaviour-neutral — nothing in core reads them, so no code path changes unless the opt-in is set. Core reports the fact, the opt-in decides what to do with it:GestureRecognizer.Manipulation.IsCoastingGestureRecognizer.LastDownStoppedInertia— informative only; the gestures of that press are still recognized exactly as beforeUIElement.LastPointerDownStoppedInertiaUIElement.PreventGestures(pointer, gestures)GestureRecognizer.ProcessDownEventgains one assignment to compute the flag; every other line is a new member. The unchanged default is pinned byWhen_PressStopsInertia_Without_OptIn_Then_TapIsRaised.Platform reach
The opt-in is honoured on the targets which use the managed pointer pipeline — every Skia target (Desktop, and Skia on Android, iOS and WebAssembly) and the WebAssembly backend. It is inert on WinAppSDK, where the callback body is
#if HAS_UNOso the property just stores its value and cross-platform XAML stays valid. On the native Android and iOS backends pointer events bubble natively, so the order the gestures are muted in has not been validated and those backends are documented as unsupported for this opt-in.The property is deliberately not gated per target: the default is unchanged unless it is set, and a setter that silently refuses a value is harder to diagnose than one documented as inert.
Implementation note
The muting needs two passes because of the order in which a press reaches the gesture recognizers: each element updates its own gestures before invoking its handlers, ancestors are visited from the closest to the root, and the original source updates its own gestures last of all. So the extension mutes the original-source→tracked-element path on the press (retroactively, those gestures already exist) and the remainder — the ancestors and the original source — on the release, which still runs before their gestures are recognized.
Validation
SamplesApp.Skia.Generic),Given_ManipulationExtensions: 3 passed.When_PressStopsInertia_Without_OptIn_Then_TapIsRaisedpins the default, i.e. the WinUI behaviour, so parity cannot regress silently.When_PressStopsInertia_With_OptIn_Then_NoTapIsRaisedOnThePathasserts no tap on the original source, an intermediate element, the coasting element and an ancestor — the four positions the two passes have to cover.When_TapAtRest_With_OptIn_Then_TapIsRaisedOnThePathasserts the opt-in leaves a normal tap alone.Given_InputManager,Given_GestureRecognizer,Given_ScrollViewer,Given_SwipeControl,Given_FlipView,Given_RefreshContainerandUno_UI_Toolkit.Given_GestureRecognizer: the recognizer reportsLastDownStoppedInertiafor the aborting press and still raises the tap, plus a no-false-positive case.DataGrid7.1.205) on Skia macOS confirmed the implicitStyledoes deliver an attached property toDataGridRowsPresenter, and that itsManipulationModeis the inertia-enabled one above.Uno.UIandUno.UI.Toolkitfor Skia, Reference, WebAssembly and iOS, and an analyzer-enabled build (noUnoFastDevBuild) ofUno.UI.ToolkitandUno.UI.RuntimeTests: 0 errors, no new warnings.Manipulation_TapStopsInertiasample (its in-app toggle flips between the default and the opt-in on the same screen).PR Checklist ✅
Screenshots Compare Test Runresults.