Skip to content

feat(toolkit): Add opt-in touch scrollbar thumb drag - #24199

Merged
ajpinedam merged 18 commits into
unoplatform:masterfrom
ajpinedam:dev/anpi/fix.wasm.scrollbar.touch.drag
Sep 1, 2026
Merged

ajpinedam merged 18 commits into
unoplatform:masterfrom
ajpinedam:dev/anpi/fix.wasm.scrollbar.touch.drag

Conversation

@ajpinedam

@ajpinedam ajpinedam commented Aug 25, 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 iOS/iPadOS WebAssembly, touching a scrollbar reveals it but dragging the thumb does not scroll — in a plain ScrollViewer and in CommunityToolkit DataGrid.

This turned out to be intended WinUI behaviour, not a bug. dxaml\xcp\dxaml\lib\ScrollBar_Partial.cpp (AttachEvents, tag winui3/release/1.6.5) calls put_IgnoreTouchInput(TRUE) on both thumbs and all eight repeat buttons — ten parts, which Uno ports one-for-one — and Thumb::put_IgnoreTouchInput exists solely for that purpose, defaulting to FALSE with ScrollBar as its only caller. WinUI also drives TouchIndicator deliberately. So a touch drag on a scrollbar thumb is not possible on WinUI by design.

The gap is nonetheless real on touch-only targets: a browser on a tablet has no mouse, so the scrollbar is the only affordance and WinUI's assumption does not hold. That makes this an enhancement, which must not change default behaviour on any target.

It ships as an opt-in Uno.UI.Toolkit attached property:

<Style TargetType="ScrollBar">
  <Setter Property="toolkit:ScrollBarExtensions.IsTouchThumbDragEnabled" Value="True" />
</Style>

Applied through an implicit Style as above it also covers scrollbars an app cannot reach directly, including DataGrid's internal bars.

This does change core code, behind the opt-in

An earlier revision tried to do this entirely from the Toolkit, by walking the template to clear IgnoreTouchInput and by pinning IndicatorMode. iPad validation showed that approach is not sound, for two reasons:

  1. ScrollBar.AttachEvents re-applies IgnoreTouchInput = true to its parts every time it attaches them — on template application and on Loaded — so anything set from outside is undone. The ScrollViewer template also defers its bars (x:Load="False"), so with Auto visibility a bar is realized only once an axis overflows, after any external code has run.
  2. IndicatorMode is driven by the ScrollViewer's visual states, i.e. at animation precedence, so a local value set from the Toolkit loses. After any finger pan the bar returned to TouchIndicator, where the template collapses the interactive root the thumb lives in.

So the opt-in is now a per-instance internal flag on ScrollBar, honoured in the two places that decide this, both gated:

  • AttachEvents applies IgnoreTouchInput = !IsTouchThumbDragEnabled to the ten parts instead of a hard-coded true — the exact line WinUI hard-codes.
  • IsConscious() becomes per-instance (ShouldUseDynamicScrollbars() && !IsTouchThumbDragEnabled), so an opted-in bar takes the same path WinUI takes when the OS "automatically hide scroll bars" setting is off: it keeps the interactive indicator instead of the thin touch one.

Default behaviour is unchanged on every target, which is pinned by a test (below). The Toolkit extension is now ~45 lines that set that flag, with no visual-tree walking and no timing assumptions.

Known limitation

While enabled the bar stays visible and interactive, so a pan started on the scrollbar drags the thumb rather than panning the content — the same as any pointer-driven scrollbar. Documented in doc/articles/Uno.UI.Toolkit.md.

Validation

  • Runtime — Skia Desktop (SamplesApp.Skia.Generic), Given_ScrollBar: 10 passed / 0 skipped.
    • Touch thumb drag for both orientations, asserting Value plus the ThumbTrack and EndScroll sequence.
    • Both a standalone ScrollBar (the DataGrid shape) and a ScrollViewer-hosted one, the latter across Visible and Auto bar visibility — Auto matters because the template defers those bars.
    • When_Touch_Panned_Then_Thumb_Is_Still_Draggable pans with a finger first, asserts the bar really reached TouchIndicator, and only then drags the thumb, so it cannot pass without entering the state that broke on device.
    • When_Reloaded_Then_Touch_Thumb_Drag_Survives covers the re-attach path from (1) above.
    • When_Touch_Drags_Thumb_Without_OptIn_Then_Value_Is_Unchanged pins the default behaviour: without opting in, a touch drag must not move the bar.
    • Fails-before/passes-after: with the core change neutered, 8 of those 10 fail — while the default-behaviour test still passes, which is the evidence the change is genuinely gated.
  • Device — validated on a physical iPad (iPadOS Safari, Skia WebAssembly) with the added manual sample ScrollViewer_TouchScrollBarDrag (category Scrolling), which has an in-page toggle for the opt-in so both states can be compared without a rebuild.
  • Compile — 0 errors.

PR Checklist ✅

@unodevops

Copy link
Copy Markdown
Contributor

@MartinZikmund

Copy link
Copy Markdown
Member

@ajpinedam is it possible to touch drag the bar on WinUI? I think that it may actually just be intended this way. I think it may be possible to confirm via WinUI C++ sources, but if it would be Uno specific, it would be better as some extension in Uno Toolkit or such

@unodevops

Copy link
Copy Markdown
Contributor

@ajpinedam

ajpinedam commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor Author

@MartinZikmund

You're right, and it's confirmed in the WinUI sources.

ScrollBar_Partial.cpp (AttachEvents, tag winui3/release/1.6.5) calls put_IgnoreTouchInput(TRUE) on both thumbs and all eight repeat buttons — ten parts, which Uno ported one-for-one. And Thumb::put_IgnoreTouchInput exists purely for that purpose (defaults to FALSE, ScrollBar is its only caller). So a touch drag on the thumb is intended WinUI behavior, not a bug. Same for TouchIndicator: WinUI drives it deliberately, so my second change diverged too.

The gap is still real on touch-only targets — a browser on a tablet has no mouse, so the scrollbar is the only affordance, and there's no WinUI equivalent — but that makes this an enhancement, not a fix, and it shouldn't change default behavior on every target.

So I'll take your suggestion: moving it out of core into an opt-in Uno.UI.Toolkit extension (an attached property on the ScrollViewer/ScrollBar). Uno.UI already has InternalsVisibleTo("Uno.UI.Toolkit"), so the Toolkit can clear IgnoreTouchInput on the thumbs, and ScrollBar.IndicatorMode is public — no core changes needed at all. I'll reshape this PR accordingly.

@ajpinedam ajpinedam changed the title fix(scrollbar): Allow touch drag of the ScrollBar thumb feat(toolkit): Add opt-in touch scrollbar thumb drag Aug 25, 2026
@unodevops

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot added area/automation Categorizes an issue or PR as relevant to project automation kind/documentation labels Aug 28, 2026
@ajpinedam
ajpinedam marked this pull request as ready for review August 28, 2026 20:33
Copilot AI lite review requested due to automatic review settings August 28, 2026 20:33

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

This PR introduces an opt-in Uno.UI.Toolkit attached property to enable touch (finger) dragging of ScrollBar thumbs on touch-only scenarios (notably iOS/iPadOS WebAssembly), while keeping default WinUI parity unchanged.

Changes:

  • Add ScrollBarExtensions.IsTouchThumbDragEnabled (Toolkit) and a corresponding internal flag on ScrollBar to reconfigure template-part touch behavior.
  • Update ScrollBar internals to honor the opt-in by keeping interactive visual states and by toggling IgnoreTouchInput on relevant template parts.
  • Add runtime tests + a SamplesApp manual test page, and document the feature in Uno.UI.Toolkit.md.

Review verdict (summary): changes needed.
Issue counts: 1 documentation/build-risk issue, 1 test-hygiene issue.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/Uno.UI/UI/Xaml/Controls/ScrollBar/ScrollBar.uno.cs Adds internal opt-in flag/property and triggers re-attach + visual refresh when toggled.
src/Uno.UI/UI/Xaml/Controls/ScrollBar/ScrollBar.mux.cs Applies opt-in by toggling IgnoreTouchInput for thumbs/repeat buttons during event attachment.
src/Uno.UI/UI/Xaml/Controls/ScrollBar/ScrollBar.h.mux.cs Treats opt-in scrollbars as “not conscious” to keep interactive indicator visible.
src/Uno.UI.Toolkit/ScrollBarExtensions.cs Introduces attached property API and (Uno-only) change callback wiring into ScrollBar.
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls_Primitives/Given_ScrollBar.cs Adds runtime tests validating opt-in behavior and default behavior; includes one ignored test documenting a limitation.
src/SamplesApp/SamplesApp.Samples/Windows_UI_Xaml_Controls/ScrollViewerTests/ScrollViewer_TouchScrollBarDrag.xaml.cs Adds manual test logic to toggle opt-in and report scrollbar state/events.
src/SamplesApp/SamplesApp.Samples/Windows_UI_Xaml_Controls/ScrollViewerTests/ScrollViewer_TouchScrollBarDrag.xaml Adds manual test UI to exercise touch thumb dragging (ScrollViewer + standalone ScrollBar).
doc/articles/Uno.UI.Toolkit.md Documents the new opt-in property and usage patterns (including implicit Style).

💡 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 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

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Suppressed comments (2)

Previously missed (1) — in code that hasn't changed since the last review.

src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls_Primitives/Given_ScrollBar.cs:4

  • System.Linq and System.Text are not used anywhere in this test file. With analyzer enforcement, unused usings can break CI (IDE0005 / CS0105). Remove them to keep the test project warning-clean.

This issue also appears on line 17 of the same file.

using System.Linq;
using System.Text;

src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls_Primitives/Given_ScrollBar.cs:17

  • Windows.UI.Input.Preview.Injection is not referenced in this file (the tests use Uno.UI.Toolkit.DevTools.Input.InputInjector instead). Remove the unused using to avoid analyzer failures.
using Windows.UI.Input.Preview.Injection;

@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

Copilot AI review requested due to automatic review settings August 30, 2026 17:28

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

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

src/SamplesApp/SamplesApp.Samples/Windows_UI_Xaml_Controls/ScrollViewerTests/ScrollViewer_TouchScrollBarDrag.xaml.cs:45

  • LayoutUpdated can fire very frequently (including while scrolling). Calling TryResolveScrollBars() on every LayoutUpdated causes repeated visual-tree walks and status updates, which can noticeably slow down this manual sample. Consider gating the call so you only search when a bar is missing and the corresponding Computed*ScrollBarVisibility indicates it should be visible (overflow), or otherwise stop polling once resolved.
		// The ScrollViewer template defers its bars (x:Load="False"), so with Auto visibility they only appear
		// once an axis actually overflows - after this page has loaded. Keep looking until they show up.
		private void OnViewportLayoutUpdated(object sender, object e) => TryResolveScrollBars();

@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 231079 has failed on Uno.UI - CI.

Copilot AI review requested due to automatic review settings August 31, 2026 15:02
@ajpinedam
ajpinedam force-pushed the dev/anpi/fix.wasm.scrollbar.touch.drag branch from 58763cc to 1dd1009 Compare August 31, 2026 15:02

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

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

Comment thread doc/articles/Uno.UI.Toolkit.md Resolved
Copilot AI review requested due to automatic review settings August 31, 2026 19:37

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

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

Suppressed comments (2)

Previously missed (2) — in code that hasn't changed since the last review.

src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls_Primitives/Given_ScrollBar.cs:126

  • This test can pass even if the injected touch never actually hits a laid-out thumb (e.g., if the template is present but the thumb has 0×0 bounds). Adding a bounds assert here makes the “default behavior unchanged” coverage more reliable and avoids false positives.
				var thumb = FindTemplateChild<Thumb>(SUT, "VerticalThumb");
				Assert.IsNotNull(thumb, "The vertical thumb should be part of the ScrollBar template.");

				finger.Press(Center(thumb.GetAbsoluteBounds()));
				finger.MoveBy(0, 50, steps: 50);

src/Uno.UI.Toolkit/ScrollBarExtensions.cs:19

  • The remark says “No effect on Windows”, but this opt-in does take effect on Uno’s managed (Skia) desktop targets which can run on Windows OS. Consider clarifying that the no-op case is WinAppSDK/native WinUI, not the Windows OS in general.
		/// WinUI has the ScrollBar parts ignore touch, as touch scrolling goes through DirectManipulation
		/// there and the bar is only an indicator. A touch-only device - a browser on a tablet most notably -
		/// has no pointer to reveal an interactive bar with, so this opts into keeping the bar in its
		/// interactive state, which also keeps it visible. No effect on Windows.
		/// </remarks>

@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

@ajpinedam
ajpinedam merged commit 84b5571 into unoplatform:master Sep 1, 2026
50 checks passed
@ajpinedam
ajpinedam deleted the dev/anpi/fix.wasm.scrollbar.touch.drag branch September 1, 2026 16:21
@ajpinedam

Copy link
Copy Markdown
Contributor Author

@Mergifyio backport release/stable/6.7

@mergify

mergify Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

backport release/stable/6.7

✅ Backports have been created

Details

@github-actions github-actions Bot mentioned this pull request Sep 2, 2026
4 of 5 tasks
agneszitte added a commit that referenced this pull request Sep 11, 2026
…6.7/pr-24199

feat(toolkit): Add opt-in touch scrollbar thumb drag (backport #24199)
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