From 83c565d9f5c84d72a239b86e07cec9616e55af06 Mon Sep 17 00:00:00 2001 From: Ramez Ragaa Date: Thu, 21 Nov 2024 18:57:07 +0200 Subject: [PATCH 1/3] fix(scrollviewer): fix scrollArgs.IsIntermediate on WASm (cherry picked from commit 84c85fe4432e85488f810993c732cd3ce118f68a) --- .../ScrollContentPresenter.wasm.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/ScrollContentPresenter.wasm.cs b/src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/ScrollContentPresenter.wasm.cs index a77cba41f6cf..2e4a0aadcabc 100644 --- a/src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/ScrollContentPresenter.wasm.cs +++ b/src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/ScrollContentPresenter.wasm.cs @@ -262,9 +262,16 @@ internal bool Set( } _pendingScrollTo = (horizontalOffset, verticalOffset); - _lastScrollToRequest = (horizontalOffset, verticalOffset); - WindowManagerInterop.ScrollTo(HtmlId, horizontalOffset, verticalOffset, disableAnimation); + try + { + _lastScrollToRequest = (horizontalOffset, verticalOffset); + WindowManagerInterop.ScrollTo(HtmlId, horizontalOffset, verticalOffset, disableAnimation); + } + finally + { + _lastScrollToRequest = (null, null); + } if (_pendingScrollTo.HasValue) { @@ -356,10 +363,6 @@ private bool OnScroll(object sender, RoutedEventArgs routedEventArgs) var isIntermediate = (_lastScrollToRequest.horizontal.HasValue && _lastScrollToRequest.horizontal.Value != horizontalOffset) || (_lastScrollToRequest.vertical.HasValue && _lastScrollToRequest.vertical.Value != verticalOffset); - if (!isIntermediate) - { - _lastScrollToRequest = (null, null); - } if (IsArrangeDirty && _pendingScrollTo is { } pending From 941760391b29f6f34d00c20ef088afc865cbeb34 Mon Sep 17 00:00:00 2001 From: Ramez Ragaa Date: Thu, 21 Nov 2024 21:36:45 +0200 Subject: [PATCH 2/3] chore: adjust fix (cherry picked from commit fa88db047cdd0e26df5275682591ff3f8a4299ea) --- .../ScrollContentPresenter.wasm.cs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/ScrollContentPresenter.wasm.cs b/src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/ScrollContentPresenter.wasm.cs index 2e4a0aadcabc..d315db50e219 100644 --- a/src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/ScrollContentPresenter.wasm.cs +++ b/src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/ScrollContentPresenter.wasm.cs @@ -262,16 +262,9 @@ internal bool Set( } _pendingScrollTo = (horizontalOffset, verticalOffset); + _lastScrollToRequest = (horizontalOffset, verticalOffset); - try - { - _lastScrollToRequest = (horizontalOffset, verticalOffset); - WindowManagerInterop.ScrollTo(HtmlId, horizontalOffset, verticalOffset, disableAnimation); - } - finally - { - _lastScrollToRequest = (null, null); - } + WindowManagerInterop.ScrollTo(HtmlId, horizontalOffset, verticalOffset, disableAnimation); if (_pendingScrollTo.HasValue) { @@ -361,8 +354,12 @@ private bool OnScroll(object sender, RoutedEventArgs routedEventArgs) var horizontalOffset = GetNativeHorizontalOffset(); var verticalOffset = GetNativeVerticalOffset(); var isIntermediate = - (_lastScrollToRequest.horizontal.HasValue && _lastScrollToRequest.horizontal.Value != horizontalOffset) || - (_lastScrollToRequest.vertical.HasValue && _lastScrollToRequest.vertical.Value != verticalOffset); + (_lastScrollToRequest.horizontal.HasValue && Math.Abs(_lastScrollToRequest.horizontal.Value - horizontalOffset) >= 1) || + (_lastScrollToRequest.vertical.HasValue && Math.Abs(_lastScrollToRequest.vertical.Value - verticalOffset) >= 1); + if (!isIntermediate) + { + _lastScrollToRequest = (null, null); + } if (IsArrangeDirty && _pendingScrollTo is { } pending From e18093475615d6c46fba380ec643893680ccb6ac Mon Sep 17 00:00:00 2001 From: Ramez Ragaa Date: Thu, 21 Nov 2024 21:37:10 +0200 Subject: [PATCH 3/3] test: add a manual test (cherry picked from commit e0f4fded01f0f187a71cdd46e2c930e506309b9f) --- .../UITests.Shared/UITests.Shared.projitems | 7 ++++++ .../ScrollViewer_IsIntermediate.xaml | 25 +++++++++++++++++++ .../ScrollViewer_IsIntermediate.xaml.cs | 19 ++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Controls/ScrollViewerTests/ScrollViewer_IsIntermediate.xaml create mode 100644 src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Controls/ScrollViewerTests/ScrollViewer_IsIntermediate.xaml.cs diff --git a/src/SamplesApp/UITests.Shared/UITests.Shared.projitems b/src/SamplesApp/UITests.Shared/UITests.Shared.projitems index 64187ccf22b5..d82b426bf30d 100644 --- a/src/SamplesApp/UITests.Shared/UITests.Shared.projitems +++ b/src/SamplesApp/UITests.Shared/UITests.Shared.projitems @@ -2466,6 +2466,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -9517,6 +9521,9 @@ ScrollViewer_Simple.xaml + + ScrollViewer_IsIntermediate.xaml + ScrollViewer_Content_Smaller_Than_Viewport.xaml diff --git a/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Controls/ScrollViewerTests/ScrollViewer_IsIntermediate.xaml b/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Controls/ScrollViewerTests/ScrollViewer_IsIntermediate.xaml new file mode 100644 index 000000000000..63c8a32ef0ea --- /dev/null +++ b/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Controls/ScrollViewerTests/ScrollViewer_IsIntermediate.xaml @@ -0,0 +1,25 @@ + + + + + Repro steps: + + 1. Scroll the ScrollViewer below using the scroll bar. You should see the status below possibly change to "Last ScrollViewerViewChangedEventArgs.IsIntermediate = true" but then it must end up on "Last ScrollViewerViewChangedEventArgs.IsIntermediate = false" + + 2. Scroll the ScrollViewer below using the mouse wheel. You should see the status below possibly change to "Last ScrollViewerViewChangedEventArgs.IsIntermediate = true" but then it must end up on "Last ScrollViewerViewChangedEventArgs.IsIntermediate = false" + + + + + + + + + diff --git a/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Controls/ScrollViewerTests/ScrollViewer_IsIntermediate.xaml.cs b/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Controls/ScrollViewerTests/ScrollViewer_IsIntermediate.xaml.cs new file mode 100644 index 000000000000..795d0d528627 --- /dev/null +++ b/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Controls/ScrollViewerTests/ScrollViewer_IsIntermediate.xaml.cs @@ -0,0 +1,19 @@ +using Microsoft.UI.Xaml.Controls; +using Uno.UI.Samples.Controls; + +namespace UITests.Windows_UI_Xaml_Controls.ScrollViewerTests +{ + [Sample("Scrolling", IsManualTest = true)] + public sealed partial class ScrollViewer_IsIntermediate : Page + { + public ScrollViewer_IsIntermediate() + { + this.InitializeComponent(); + } + + private void ScrollViewer_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e) + { + statusTb.Text = $"Last ScrollViewerViewChangedEventArgs.IsIntermediate = {e.IsIntermediate}"; + } + } +}