Skip to content

Commit 7101d4e

Browse files
kekekeksdanwalmsley
authored andcommitted
Merge pull request #6894 from YohDeadfall/optimize-gestures
Setting weak reference target instead of field
1 parent 25de554 commit 7101d4e

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/Avalonia.Input/Gestures.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static class Gestures
3030
"ScrollGestureEnded", RoutingStrategies.Bubble, typeof(Gestures));
3131

3232
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
33-
private static WeakReference<IInteractive> s_lastPress = new WeakReference<IInteractive>(null);
33+
private static readonly WeakReference<IInteractive> s_lastPress = new WeakReference<IInteractive>(null);
3434
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
3535

3636
static Gestures()
@@ -86,16 +86,15 @@ private static void PointerPressed(RoutedEventArgs ev)
8686
#pragma warning restore CS0618 // Type or member is obsolete
8787
if (clickCount <= 1)
8888
{
89-
s_lastPress = new WeakReference<IInteractive>(ev.Source);
89+
s_lastPress.SetTarget(ev.Source);
9090
}
91-
else if (s_lastPress != null && clickCount == 2 && e.GetCurrentPoint(visual).Properties.IsLeftButtonPressed)
91+
else if (clickCount == 2 && e.GetCurrentPoint(visual).Properties.IsLeftButtonPressed)
9292
{
9393
if (s_lastPress.TryGetTarget(out var target) && target == e.Source)
9494
{
9595
e.Source.RaiseEvent(new TappedEventArgs(DoubleTappedEvent, e));
9696
}
9797
}
98-
9998
}
10099
}
101100

0 commit comments

Comments
 (0)