Skip to content

feat: Add opt-in press-to-stop-momentum for ManipulationMode panning - #24282

Merged
ajpinedam merged 10 commits into
unoplatform:masterfrom
ajpinedam:dev/anpi/fix.wasm.scroll.tap
Sep 2, 2026
Merged

ajpinedam merged 10 commits into
unoplatform:masterfrom
ajpinedam:dev/anpi/fix.wasm.scroll.tap

Conversation

@ajpinedam

@ajpinedam ajpinedam commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

GitHub Issue: Tracked internally (customer-reported). No public issue.

PR Type:

✨ Feature

What changed? 🚀

A customer reported that on a tablet, tapping a CommunityToolkit DataGrid while 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 DataGrid pans its rows through the ManipulationMode of its DataGridRowsPresenter (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:

  • interaction contexts are keyed per 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;
  • the tap-suppression guard that does exist — GestureOutputMapper::OnTapped/OnSecondaryTapped/OnHolding dropping the message when IsInteractionStopping() && IsInteractionStopped() — is armed only by ElementGestureTracker::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 ScrollViewer is 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 the UIElement.ManipulationMode path 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:

<Border ManipulationMode="TranslateY,TranslateInertia"
        toolkit:ManipulationExtensions.IsTapToStopInertiaEnabled="True">

While enabled, the press that aborts the inertia raises no Tapped, DoubleTapped, RightTapped or Holding on the element, its ancestors or its descendants; a tap at rest is unaffected. It is a no-op on Windows.

Applied through an implicit Style it also reaches panning elements an app cannot address directly — including DataGrid's DataGridRowsPresenter, which is the customer's actual case:

<Style TargetType="primitives:DataGridRowsPresenter">
    <Setter Property="toolkit:ManipulationExtensions.IsTapToStopInertiaEnabled" Value="True" />
</Style>

This does change core code, and the default is unchanged

The Toolkit cannot observe what it needs on its own, so Uno.UI gains 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.IsCoasting
  • GestureRecognizer.LastDownStoppedInertia — informative only; the gestures of that press are still recognized exactly as before
  • UIElement.LastPointerDownStoppedInertia
  • UIElement.PreventGestures(pointer, gestures)

GestureRecognizer.ProcessDownEvent gains one assignment to compute the flag; every other line is a new member. The unchanged default is pinned by When_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_UNO so 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

  • Runtime — Skia Desktop (SamplesApp.Skia.Generic), Given_ManipulationExtensions: 3 passed.
    • When_PressStopsInertia_Without_OptIn_Then_TapIsRaised pins the default, i.e. the WinUI behaviour, so parity cannot regress silently.
    • When_PressStopsInertia_With_OptIn_Then_NoTapIsRaisedOnThePath asserts 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_TapIsRaisedOnThePath asserts the opt-in leaves a normal tap alone.
    • Both halves of the muting are load-bearing: removing the retroactive pass fails on the intermediate element, removing the forward flag fails on the original source.
  • Runtime (regression) — 92 passed / 13 skipped across Given_InputManager, Given_GestureRecognizer, Given_ScrollViewer, Given_SwipeControl, Given_FlipView, Given_RefreshContainer and Uno_UI_Toolkit.
  • Unit — Given_GestureRecognizer: the recognizer reports LastDownStoppedInertia for the aborting press and still raises the tap, plus a no-false-positive case.
  • Against the customer's repro — a rebuilt copy of the reported project (real DataGrid 7.1.205) on Skia macOS confirmed the implicit Style does deliver an attached property to DataGridRowsPresenter, and that its ManipulationMode is the inertia-enabled one above.
  • Compile — Uno.UI and Uno.UI.Toolkit for Skia, Reference, WebAssembly and iOS, and an analyzer-enabled build (no UnoFastDevBuild) of Uno.UI.Toolkit and Uno.UI.RuntimeTests: 0 errors, no new warnings.
  • Device — confirmed on iPadOS against a LAN-served WebAssembly Skia SamplesApp build of this branch, through the Manipulation_TapStopsInertia sample (its in-app toggle flips between the default and the opt-in on the same screen).

PR Checklist ✅

@github-actions github-actions Bot added area/automation Categorizes an issue or PR as relevant to project automation kind/documentation labels Aug 29, 2026
@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

@ajpinedam
ajpinedam marked this pull request as ready for review August 31, 2026 21:16
Copilot AI lite review requested due to automatic review settings August 31, 2026 21:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.IsTapToStopInertiaEnabled to 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.

@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

Copilot AI review requested due to automatic review settings September 1, 2026 21:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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

Copilot AI review requested due to automatic review settings September 1, 2026 21:43
@ajpinedam
ajpinedam force-pushed the dev/anpi/fix.wasm.scroll.tap branch from 131769c to 40e19e8 Compare September 1, 2026 21:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

Copilot AI review requested due to automatic review settings September 2, 2026 04:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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

  • LastDownStoppedInertia is computed before the gesture is created, but when the down is immediately completed (e.g., double-tap is recognized on Down), ProcessDownEvent returns early and never calls Manipulation.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

@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

@mergify

mergify Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@ajpinedam
ajpinedam merged commit dac70ed into unoplatform:master Sep 2, 2026
49 checks passed
@ajpinedam
ajpinedam deleted the dev/anpi/fix.wasm.scroll.tap branch September 2, 2026 14:24
@github-actions github-actions Bot mentioned this pull request Sep 2, 2026
4 of 5 tasks
@agneszitte

Copy link
Copy Markdown
Member

@Mergifyio backport release/stable/6.7

@mergify

mergify Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

backport release/stable/6.7

✅ Backports have been created

Details

agneszitte added a commit that referenced this pull request Sep 11, 2026
…6.7/pr-24282

feat: Add opt-in press-to-stop-momentum for ManipulationMode panning (backport #24282)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/automation Categorizes an issue or PR as relevant to project automation kind/documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants