Skip to content

Commit

Permalink
fix(scrollviewer): make scrolling cancelable when Handled = true on WASM
Browse files Browse the repository at this point in the history
  • Loading branch information
ramezgerges committed Oct 26, 2023
1 parent 2af7b1a commit 1c45a25
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Runtime.CompilerServices;
using System.Text;
using Windows.Foundation;
using Windows.UI.Xaml.Input;
using Uno.UI.Xaml;

using Uno.UI.Extensions;
Expand Down Expand Up @@ -183,6 +184,17 @@ private protected override void OnLoaded()
base.OnLoaded();
RestoreScroll();
RegisterEventHandler("scroll", (EventHandler)OnScroll, GenericEventHandlers.RaiseEventHandler);

// a workaround to make scrolling cancelable on WASM
AddHandler(PointerWheelChangedEvent, new PointerEventHandler(CancelNativeScrollIfHandled), true);
}

private void CancelNativeScrollIfHandled(object _, PointerRoutedEventArgs args)
{
if (args.Handled)
{
((IHtmlHandleableRoutedEventArgs)args).HandledResult |= HtmlEventDispatchResult.PreventDefault;
}
}

private void RestoreScroll()
Expand All @@ -204,6 +216,8 @@ private protected override void OnUnloaded()
base.OnUnloaded();
UnregisterEventHandler("scroll", (EventHandler)OnScroll, GenericEventHandlers.RaiseEventHandler);

RemoveHandler(PointerWheelChangedEvent, new PointerEventHandler(CancelNativeScrollIfHandled));

if (_rootEltUsedToProcessScrollTo is { } rootElt)
{
rootElt.LayoutUpdated -= TryProcessScrollTo;
Expand Down

0 comments on commit 1c45a25

Please sign in to comment.