Browse Source

add HoldWaitDuration to IPlatformSettings

pull/9652/head
Emmanuel Hansen 3 years ago
parent
commit
8516308e63
  1. 16
      src/Avalonia.Base/Input/Gestures.cs
  2. 2
      src/Avalonia.Base/Platform/DefaultPlatformSettings.cs
  3. 2
      src/Avalonia.Base/Platform/IPlatformSettings.cs
  4. 2
      src/Windows/Avalonia.Win32/Win32Platform.cs

16
src/Avalonia.Base/Input/Gestures.cs

@ -148,14 +148,18 @@ namespace Avalonia.Input
s_holdCancellationToken = new CancellationTokenSource();
var token = s_holdCancellationToken.Token;
var settings = AvaloniaLocator.Current.GetService<IPlatformSettings>();
DispatcherTimer.RunOnce(() =>
if (settings != null)
{
if (!token.IsCancellationRequested && e.Source is InputElement i && i.IsHoldingEnabled && ( e.Pointer.Type != PointerType.Mouse || i.IsHoldWithMouseEnabled))
DispatcherTimer.RunOnce(() =>
{
s_isHolding = true;
i.RaiseEvent(new HoldingRoutedEventArgs(HoldingState.Started, s_lastPressPoint, s_lastPointer.Type));
}
}, TimeSpan.FromMilliseconds(300));
if (!token.IsCancellationRequested && e.Source is InputElement i && i.IsHoldingEnabled && (e.Pointer.Type != PointerType.Mouse || i.IsHoldWithMouseEnabled))
{
s_isHolding = true;
i.RaiseEvent(new HoldingRoutedEventArgs(HoldingState.Started, s_lastPressPoint, s_lastPointer.Type));
}
}, settings.HoldWaitDuration);
}
}
else if (e.ClickCount % 2 == 0 && e.GetCurrentPoint(visual).Properties.IsLeftButtonPressed)
{

2
src/Avalonia.Base/Platform/DefaultPlatformSettings.cs

@ -26,5 +26,7 @@ namespace Avalonia.Platform
};
}
public TimeSpan GetDoubleTapTime(PointerType type) => TimeSpan.FromMilliseconds(500);
public TimeSpan HoldWaitDuration { get; set; } = TimeSpan.FromMilliseconds(300);
}
}

2
src/Avalonia.Base/Platform/IPlatformSettings.cs

@ -27,5 +27,7 @@ namespace Avalonia.Platform
/// tap gesture.
/// </summary>
TimeSpan GetDoubleTapTime(PointerType type);
TimeSpan HoldWaitDuration { get; set; }
}
}

2
src/Windows/Avalonia.Win32/Win32Platform.cs

@ -258,6 +258,8 @@ namespace Avalonia.Win32
public bool CurrentThreadIsLoopThread => _uiThread == Thread.CurrentThread;
public TimeSpan HoldWaitDuration { get; set; } = TimeSpan.FromMilliseconds(300);
public event Action<DispatcherPriority?> Signaled;
public event EventHandler<ShutdownRequestedEventArgs> ShutdownRequested;

Loading…
Cancel
Save