Skip to content

Commit 9e4065f

Browse files
Merge pull request #3611 from RosarioPulella/range-selector-remove-animation
Remove animations from RangeSelector
2 parents a8e23a4 + fad4d7b commit 9e4065f

File tree

3 files changed

+15
-24
lines changed

3 files changed

+15
-24
lines changed

Microsoft.Toolkit.Uwp.UI.Controls/RangeSelector/RangeSelector.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6+
using Microsoft.Toolkit.Uwp.UI.Extensions;
67
using Windows.Foundation;
78
using Windows.System;
89
using Windows.UI.Xaml;
@@ -35,6 +36,7 @@ public partial class RangeSelector : Control
3536
private const double DefaultMinimum = 0.0;
3637
private const double DefaultMaximum = 1.0;
3738
private const double DefaultStepFrequency = 1;
39+
private static readonly TimeSpan TimeToHideToolTipOnKeyUp = TimeSpan.FromSeconds(1);
3840

3941
/// <summary>
4042
/// Identifies the Minimum dependency property.
@@ -61,6 +63,8 @@ public partial class RangeSelector : Control
6163
/// </summary>
6264
public static readonly DependencyProperty StepFrequencyProperty = DependencyProperty.Register(nameof(StepFrequency), typeof(double), typeof(RangeSelector), new PropertyMetadata(DefaultStepFrequency));
6365

66+
private readonly DispatcherQueueTimer keyDebounceTimer = DispatcherQueue.GetForCurrentThread().CreateTimer();
67+
6468
private Border _outOfRangeContentContainer;
6569
private Rectangle _activeRectangle;
6670
private Thumb _minThumb;
@@ -247,7 +251,9 @@ private void Thumb_KeyUp(object sender, KeyRoutedEventArgs e)
247251
case VirtualKey.Right:
248252
if (_toolTip != null)
249253
{
250-
_toolTip.Visibility = Visibility.Collapsed;
254+
keyDebounceTimer.Debounce(
255+
() => _toolTip.Visibility = Visibility.Collapsed,
256+
TimeToHideToolTipOnKeyUp);
251257
}
252258

253259
e.Handled = true;

Microsoft.Toolkit.Uwp.UI.Controls/RangeSelector/RangeSelector.xaml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3-
xmlns:animations="using:Microsoft.Toolkit.Uwp.UI.Animations"
43
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls">
54

65
<Style x:Key="SliderThumbStyle"
@@ -58,20 +57,6 @@
5857
BorderBrush="{ThemeResource SystemControlForegroundChromeHighBrush}"
5958
BorderThickness="1"
6059
Visibility="Collapsed">
61-
<animations:Implicit.ShowAnimations>
62-
<animations:OpacityAnimation From="0"
63-
To="1.0"
64-
Duration="0:0:0.3" />
65-
</animations:Implicit.ShowAnimations>
66-
67-
<animations:Implicit.HideAnimations>
68-
<animations:ScalarAnimation Target="Opacity"
69-
To="0"
70-
Duration="0:0:1">
71-
<animations:ScalarKeyFrame Key="0.7"
72-
Value="1.0" />
73-
</animations:ScalarAnimation>
74-
</animations:Implicit.HideAnimations>
7560
<TextBlock x:Name="ToolTipText"
7661
Margin="8"
7762
Foreground="{ThemeResource SystemControlForegroundBaseHighBrush}" />

Microsoft.Toolkit.Uwp.UI/Extensions/DispatcherTimerExtensions.cs renamed to Microsoft.Toolkit.Uwp.UI/Extensions/DispatcherQueueTimerExtensions.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44

55
using System;
66
using System.Collections.Concurrent;
7-
using Windows.UI.Xaml;
7+
using Windows.System;
88

99
namespace Microsoft.Toolkit.Uwp.UI.Extensions
1010
{
1111
/// <summary>
12-
/// Set of extention methods for using <see cref="DispatcherTimer"/>.
12+
/// Set of extention methods for using <see cref="DispatcherQueueTimer"/>.
1313
/// </summary>
14-
public static class DispatcherTimerExtensions
14+
public static class DispatcherQueueTimerExtensions
1515
{
16-
private static ConcurrentDictionary<DispatcherTimer, Action> _debounceInstances = new ConcurrentDictionary<DispatcherTimer, Action>();
16+
private static ConcurrentDictionary<DispatcherQueueTimer, Action> _debounceInstances = new ConcurrentDictionary<DispatcherQueueTimer, Action>();
1717

1818
/// <summary>
1919
/// <para>Used to debounce (rate-limit) an event. The action will be postponed and executed after the interval has elapsed. At the end of the interval, the function will be called with the arguments that were passed most recently to the debounced function.</para>
@@ -27,18 +27,18 @@ public static class DispatcherTimerExtensions
2727
/// <param name="immediate">Determines if the action execute on the leading edge instead of trailing edge.</param>
2828
/// <example>
2929
/// <code>
30-
/// private DispatcherTimer _typeTimer = new DispatcherTimer();
30+
/// private DispatcherQueueTimer _typeTimer = new DispatcherQueueTimer();
3131
///
3232
/// _typeTimer.Debounce(async () =>
3333
/// {
3434
/// // Only executes this code after 0.3 seconds have elapsed since last trigger.
3535
/// }, TimeSpan.FromSeconds(0.3));
3636
/// </code>
3737
/// </example>
38-
public static void Debounce(this DispatcherTimer timer, Action action, TimeSpan interval, bool immediate = false)
38+
public static void Debounce(this DispatcherQueueTimer timer, Action action, TimeSpan interval, bool immediate = false)
3939
{
4040
// Check and stop any existing timer
41-
var timeout = timer.IsEnabled;
41+
var timeout = timer.IsRunning;
4242
if (timeout)
4343
{
4444
timer.Stop();
@@ -72,7 +72,7 @@ public static void Debounce(this DispatcherTimer timer, Action action, TimeSpan
7272
private static void Timer_Tick(object sender, object e)
7373
{
7474
// This event is only registered/run if we weren't in immediate mode above
75-
if (sender is DispatcherTimer timer)
75+
if (sender is DispatcherQueueTimer timer)
7676
{
7777
timer.Tick -= Timer_Tick;
7878
timer.Stop();

0 commit comments

Comments
 (0)