Skip to content

Commit de72a96

Browse files
emmaussmaxkatz6
authored andcommitted
Use tap size as default size for scrolling start. reset IsGestureRecognitionSkipped 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
1 parent 8ae5f6e commit de72a96

File tree

5 files changed

+10
-4
lines changed

5 files changed

+10
-4
lines changed

src/Avalonia.Base/Input/GestureRecognizers/ScrollGestureRecognizer.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Diagnostics;
3+
using Avalonia.Platform;
34
using Avalonia.Threading;
45

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

1820
private bool _scrolling;
1921
private Point _trackedRootPoint;
@@ -54,7 +56,7 @@ public class ScrollGestureRecognizer : GestureRecognizer
5456
public static readonly DirectProperty<ScrollGestureRecognizer, int> ScrollStartDistanceProperty =
5557
AvaloniaProperty.RegisterDirect<ScrollGestureRecognizer, int>(nameof(ScrollStartDistance),
5658
o => o.ScrollStartDistance, (o, v) => o.ScrollStartDistance = v,
57-
unsetValue: 30);
59+
unsetValue: s_defaultScrollStartDistance);
5860

5961
/// <summary>
6062
/// Gets or sets a value indicating whether the content can be scrolled horizontally.

src/Avalonia.Base/Input/MouseDevice.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ private bool MouseUp(IMouseDevice device, ulong timestamp, IInputRoot root, Poin
205205
{
206206
_pointer.Capture(null);
207207
_pointer.CaptureGestureRecognizer(null);
208+
_pointer.IsGestureRecognitionSkipped = false;
208209
_lastMouseDownButton = default;
209210
}
210211
return e.Handled;

src/Avalonia.Base/Input/PenDevice.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ private bool PenUp(Pointer pointer, ulong timestamp,
167167
{
168168
pointer.Capture(null);
169169
pointer.CaptureGestureRecognizer(null);
170+
pointer.IsGestureRecognitionSkipped = false;
170171
_lastMouseDownButton = default;
171172
}
172173

src/Avalonia.Base/Input/TouchDevice.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ public void ProcessRawEvent(RawInputEventArgs ev)
119119
{
120120
pointer?.Capture(null);
121121
pointer?.CaptureGestureRecognizer(null);
122+
if (pointer != null)
123+
pointer.IsGestureRecognitionSkipped = false;
122124
}
123125
}
124126

tests/Avalonia.UnitTests/TouchTestHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ public void Up(Interactive target, Interactive source, Point position = default,
4949
else
5050
source.RaiseEvent(e);
5151

52-
_pointer.Capture(null);
53-
_pointer.CaptureGestureRecognizer(null);
52+
Cancel();
5453
}
5554

5655
public void Tap(Interactive target, Point position = default, KeyModifiers modifiers = default)
@@ -66,6 +65,7 @@ public void Cancel()
6665
{
6766
_pointer.Capture(null);
6867
_pointer.CaptureGestureRecognizer(null);
68+
_pointer.IsGestureRecognitionSkipped = false;
6969
}
7070
}
7171
}

0 commit comments

Comments
 (0)