From 50cc02182b0938d0b1c111bd0bc4946689fd0d52 Mon Sep 17 00:00:00 2001 From: Yoh Deadfall Date: Tue, 9 Nov 2021 13:40:30 +0300 Subject: [PATCH] Setting weak reference target instead of field --- src/Avalonia.Input/Gestures.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Avalonia.Input/Gestures.cs b/src/Avalonia.Input/Gestures.cs index 8d74001309..639b4ef117 100644 --- a/src/Avalonia.Input/Gestures.cs +++ b/src/Avalonia.Input/Gestures.cs @@ -30,7 +30,7 @@ namespace Avalonia.Input "ScrollGestureEnded", RoutingStrategies.Bubble, typeof(Gestures)); #pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type. - private static WeakReference s_lastPress = new WeakReference(null); + private static readonly WeakReference s_lastPress = new WeakReference(null); #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. static Gestures() @@ -86,16 +86,15 @@ namespace Avalonia.Input #pragma warning restore CS0618 // Type or member is obsolete if (clickCount <= 1) { - s_lastPress = new WeakReference(ev.Source); + s_lastPress.SetTarget(ev.Source); } - else if (s_lastPress != null && clickCount == 2 && e.GetCurrentPoint(visual).Properties.IsLeftButtonPressed) + else if (clickCount == 2 && e.GetCurrentPoint(visual).Properties.IsLeftButtonPressed) { if (s_lastPress.TryGetTarget(out var target) && target == e.Source) { e.Source.RaiseEvent(new TappedEventArgs(DoubleTappedEvent, e)); } } - } }