Skip to content

Commit

Permalink
fix: Avoid subscribing to touch scroll events twice
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Dec 4, 2024
1 parent 2f3ac18 commit 726fb91
Showing 1 changed file with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using Windows.Devices.Input;
using Windows.Foundation;
using Uno.UI.Xaml;
using Uno.Disposables;


#if HAS_UNO_WINUI
using _PointerDeviceType = global::Microsoft.UI.Input.PointerDeviceType;
Expand Down Expand Up @@ -56,6 +58,8 @@ public bool CanVerticallyScroll

private object RealContent => Content;

private readonly SerialDisposable _eventSubscriptions = new();

partial void InitializePartial()
{
#if __SKIA__
Expand All @@ -71,6 +75,8 @@ partial void InitializePartial()

private void HookScrollEvents(ScrollViewer sv)
{
UnhookScrollEvents(sv);

// Note: the way WinUI does scrolling is very different, and doesn't use
// PointerWheelChanged changes, etc.
// We can either subscribe on the ScrollViewer or the SCP directly, but due to
Expand All @@ -87,16 +93,21 @@ private void HookScrollEvents(ScrollViewer sv)
ManipulationStarted += TouchScrollStarted;
ManipulationDelta += UpdateTouchScroll;
ManipulationCompleted += CompleteTouchScroll;

_eventSubscriptions.Disposable = Disposable.Create(() =>
{
sv.PointerWheelChanged -= PointerWheelScroll;

ManipulationStarting -= PrepareTouchScroll;
ManipulationStarted -= TouchScrollStarted;
ManipulationDelta -= UpdateTouchScroll;
ManipulationCompleted -= CompleteTouchScroll;
});
}

private void UnhookScrollEvents(ScrollViewer sv)
{
sv.PointerWheelChanged -= PointerWheelScroll;

ManipulationStarting -= PrepareTouchScroll;
ManipulationStarted -= TouchScrollStarted;
ManipulationDelta -= UpdateTouchScroll;
ManipulationCompleted -= CompleteTouchScroll;
_eventSubscriptions.Disposable = null;
}

private protected override void OnLoaded()
Expand Down

0 comments on commit 726fb91

Please sign in to comment.