Skip to content

Commit

Permalink
fix(pointers): Improve relialibilty of hold gesture by always startin…
Browse files Browse the repository at this point in the history
…g a timer on press when hold has been enabled.
  • Loading branch information
dr1rrb committed Oct 22, 2021
1 parent 5094775 commit 4d18f58
Showing 1 changed file with 10 additions and 29 deletions.
39 changes: 10 additions & 29 deletions src/Uno.UWP/UI/Input/GestureRecognizer.Gesture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public Gesture(GestureRecognizer recognizer, PointerPoint down)
{
IsCompleted = true;
}
else
else if (SupportsHolding())
{
StartHoldingTimer();
}
Expand Down Expand Up @@ -248,38 +248,19 @@ private void TryEndHolding(HoldingState state)

#region Holding timer
private bool SupportsHolding()
{
switch (PointerType)
{
case PointerDeviceType.Mouse: return _settings.HasFlag(GestureSettings.HoldWithMouse);
default: return _settings.HasFlag(GestureSettings.Hold);
}
}

private bool NeedsHoldingTimer()
{
// When possible we don't start a timer for the Holding event, instead we rely on the fact that
// we get a lot of small moves due to the lack of precision of the capture device (pen and touch).
// Note: We rely on the same side effect for Drag detection (cf. Manipulation.IsBeginningOfDragManipulation).

switch (PointerType)
=> PointerType switch
{
case PointerDeviceType.Mouse: return _settings.HasFlag(GestureSettings.HoldWithMouse);
case PointerDeviceType.Touch when DeviceHelper.IsSimulator: return true;
default: return false;
}
}
PointerDeviceType.Mouse => _settings.HasFlag(GestureSettings.HoldWithMouse),
_ => _settings.HasFlag(GestureSettings.Hold)
};

private void StartHoldingTimer()
{
if (NeedsHoldingTimer())
{
_holdingTimer = DispatcherQueue.GetForCurrentThread().CreateTimer();
_holdingTimer.Interval = TimeSpan.FromTicks(HoldMinDelayTicks);
_holdingTimer.State = this;
_holdingTimer.Tick += OnHoldingTimerTick;
_holdingTimer.Start();
}
_holdingTimer = DispatcherQueue.GetForCurrentThread().CreateTimer();
_holdingTimer.Interval = TimeSpan.FromTicks(HoldMinDelayTicks);
_holdingTimer.State = this;
_holdingTimer.Tick += OnHoldingTimerTick;
_holdingTimer.Start();
}

private void StopHoldingTimer()
Expand Down

0 comments on commit 4d18f58

Please sign in to comment.