Skip to content

Commit

Permalink
perf: [Wasm] Register on ScrollContentPresenter pointer events only w…
Browse files Browse the repository at this point in the history
…hen native
  • Loading branch information
jeromelaban committed May 7, 2021
1 parent ac88fe1 commit d25f9cc
Showing 1 changed file with 30 additions and 9 deletions.
Expand Up @@ -19,6 +19,7 @@ public partial class ScrollContentPresenter : ContentPresenter, IScrollContentPr
{
private ScrollBarVisibility _verticalScrollBarVisibility;
private ScrollBarVisibility _horizontalScrollBarVisibility;
private bool _eventsRegistered;

internal Size ScrollBarSize
{
Expand All @@ -32,13 +33,29 @@ internal Size ScrollBarSize

public ScrollContentPresenter()
{
PointerReleased += ScrollViewer_PointerReleased;
PointerPressed += ScrollViewer_PointerPressed;
PointerCanceled += ScrollContentPresenter_PointerCanceled;
PointerMoved += ScrollContentPresenter_PointerMoved;
PointerEntered += ScrollContentPresenter_PointerEntered;
PointerExited += ScrollContentPresenter_PointerExited;
PointerWheelChanged += ScrollContentPresenter_PointerWheelChanged;
}

private void TryRegisterEvents(ScrollBarVisibility visibility)
{

if (
!_eventsRegistered
&& (visibility == ScrollBarVisibility.Auto || visibility == ScrollBarVisibility.Visible))
{
// Those events are only needed when native scrollbars are used, in order to handle
// pointer events on the native scrolbars themselves. See HandlePointerEvent for
// more details.

_eventsRegistered = true;

PointerReleased += ScrollViewer_PointerReleased;
PointerPressed += ScrollViewer_PointerPressed;
PointerCanceled += ScrollContentPresenter_PointerCanceled;
PointerMoved += ScrollContentPresenter_PointerMoved;
PointerEntered += ScrollContentPresenter_PointerEntered;
PointerExited += ScrollContentPresenter_PointerExited;
PointerWheelChanged += ScrollContentPresenter_PointerWheelChanged;
}
}

private void ScrollContentPresenter_PointerWheelChanged(object sender, Input.PointerRoutedEventArgs e)
Expand Down Expand Up @@ -79,8 +96,8 @@ private void HandlePointerEvent(Input.PointerRoutedEventArgs e)
return;
}

// The events coming from the scrollbars are bubbled up
// to the parents, as those are not (yet) XAML elements.
// The events coming from the native scrollbars are bubbled up
// to the parents, as those are not XAML elements.
// This can cause issues for popups with scrollable content and
// light dismiss patterns.
var position = e.GetCurrentPoint(this).Position;
Expand All @@ -105,6 +122,8 @@ internal ScrollBarVisibility VerticalScrollBarVisibility
{
_verticalScrollBarVisibility = value;
SetClasses(VerticalVisibilityClasses, (int)value);

TryRegisterEvents(value);
}
}
}
Expand All @@ -120,6 +139,8 @@ internal ScrollBarVisibility HorizontalScrollBarVisibility
{
_horizontalScrollBarVisibility = value;
SetClasses(HorizontalVisibilityClasses, (int)value);

TryRegisterEvents(value);
}
}
}
Expand Down

0 comments on commit d25f9cc

Please sign in to comment.