Skip to content

Commit

Permalink
Use tap size as default size for scrolling start. reset IsGestureReco…
Browse files Browse the repository at this point in the history
…gnitionSkipped when pointer is released (#15524)

* use tap size as default size for scrolling start. reset IsGestureRecognitionSkipped when pointer is released

* use static default constant for scroll distance

* fix typo
  • Loading branch information
emmauss authored and maxkatz6 committed May 8, 2024
1 parent 8ae5f6e commit de72a96
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
using Avalonia.Platform;
using Avalonia.Threading;

namespace Avalonia.Input.GestureRecognizers
Expand All @@ -13,7 +14,8 @@ public class ScrollGestureRecognizer : GestureRecognizer
private bool _canHorizontallyScroll;
private bool _canVerticallyScroll;
private bool _isScrollInertiaEnabled;
private int _scrollStartDistance = 30;
private readonly static int s_defaultScrollStartDistance = (int)((AvaloniaLocator.Current?.GetService<IPlatformSettings>()?.GetTapSize(PointerType.Touch).Height ?? 10) / 2);
private int _scrollStartDistance = s_defaultScrollStartDistance;

private bool _scrolling;
private Point _trackedRootPoint;
Expand Down Expand Up @@ -54,7 +56,7 @@ public class ScrollGestureRecognizer : GestureRecognizer
public static readonly DirectProperty<ScrollGestureRecognizer, int> ScrollStartDistanceProperty =
AvaloniaProperty.RegisterDirect<ScrollGestureRecognizer, int>(nameof(ScrollStartDistance),
o => o.ScrollStartDistance, (o, v) => o.ScrollStartDistance = v,
unsetValue: 30);
unsetValue: s_defaultScrollStartDistance);

/// <summary>
/// Gets or sets a value indicating whether the content can be scrolled horizontally.
Expand Down
1 change: 1 addition & 0 deletions src/Avalonia.Base/Input/MouseDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ private bool MouseUp(IMouseDevice device, ulong timestamp, IInputRoot root, Poin
{
_pointer.Capture(null);
_pointer.CaptureGestureRecognizer(null);
_pointer.IsGestureRecognitionSkipped = false;
_lastMouseDownButton = default;
}
return e.Handled;
Expand Down
1 change: 1 addition & 0 deletions src/Avalonia.Base/Input/PenDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ private bool PenUp(Pointer pointer, ulong timestamp,
{
pointer.Capture(null);
pointer.CaptureGestureRecognizer(null);
pointer.IsGestureRecognitionSkipped = false;
_lastMouseDownButton = default;
}

Expand Down
2 changes: 2 additions & 0 deletions src/Avalonia.Base/Input/TouchDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ public void ProcessRawEvent(RawInputEventArgs ev)
{
pointer?.Capture(null);
pointer?.CaptureGestureRecognizer(null);
if (pointer != null)
pointer.IsGestureRecognitionSkipped = false;
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Avalonia.UnitTests/TouchTestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ public void Up(Interactive target, Interactive source, Point position = default,
else
source.RaiseEvent(e);

_pointer.Capture(null);
_pointer.CaptureGestureRecognizer(null);
Cancel();
}

public void Tap(Interactive target, Point position = default, KeyModifiers modifiers = default)
Expand All @@ -66,6 +65,7 @@ public void Cancel()
{
_pointer.Capture(null);
_pointer.CaptureGestureRecognizer(null);
_pointer.IsGestureRecognitionSkipped = false;
}
}
}

0 comments on commit de72a96

Please sign in to comment.