Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for controling delay of scrollbar hide/show. #6379

Merged
merged 1 commit into from
Aug 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions src/Avalonia.Controls/Primitives/ScrollBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ public class ScrollBar : RangeBase
public static readonly StyledProperty<bool> AllowAutoHideProperty =
AvaloniaProperty.Register<ScrollBar, bool>(nameof(AllowAutoHide), true);

/// <summary>
/// Defines the <see cref="HideDelay"/> property.
/// </summary>
public static readonly StyledProperty<TimeSpan> HideDelayProperty =
AvaloniaProperty.Register<ScrollBar, TimeSpan>(nameof(HideDelay), TimeSpan.FromSeconds(2));

/// <summary>
/// Defines the <see cref="ShowDelay"/> property.
/// </summary>
public static readonly StyledProperty<TimeSpan> ShowDelayProperty =
AvaloniaProperty.Register<ScrollBar, TimeSpan>(nameof(ShowDelay), TimeSpan.FromSeconds(0.5));

private Button _lineUpButton;
private Button _lineDownButton;
private Button _pageUpButton;
Expand Down Expand Up @@ -126,6 +138,24 @@ public bool AllowAutoHide
get => GetValue(AllowAutoHideProperty);
set => SetValue(AllowAutoHideProperty, value);
}

/// <summary>
/// Gets a value that determines how long will be the hide delay after user stops interacting with the scrollbar.
/// </summary>
public TimeSpan HideDelay
{
get => GetValue(HideDelayProperty);
set => SetValue(HideDelayProperty, value);
}

/// <summary>
/// Gets a value that determines how long will be the show delay when user starts interacting with the scrollbar.
/// </summary>
public TimeSpan ShowDelay
{
get => GetValue(ShowDelayProperty);
set => SetValue(ShowDelayProperty, value);
}

public event EventHandler<ScrollEventArgs> Scroll;

Expand Down Expand Up @@ -296,12 +326,12 @@ private void UpdateIsExpandedState()

private void CollapseAfterDelay()
{
InvokeAfterDelay(Collapse, TimeSpan.FromSeconds(2));
InvokeAfterDelay(Collapse, HideDelay);
}

private void ExpandAfterDelay()
{
InvokeAfterDelay(Expand, TimeSpan.FromMilliseconds(400));
InvokeAfterDelay(Expand, ShowDelay);
}

private void Collapse()
Expand Down