-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[Windows][GestureManager] Unsubscribe control tap events only if they were subscribed #23976
[Windows][GestureManager] Unsubscribe control tap events only if they were subscribed #23976
Conversation
Hey there @MartyIX! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
a487bef
to
2547cfc
Compare
|
||
ClearContainerEventHandlers(); | ||
|
||
if (_element != null) | ||
if (_element is View && ElementGestureRecognizers is not null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just modernize this part a bit using pattern matching and make it less nested.
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
|
||
ClearContainerEventHandlers(); | ||
|
||
if (_element != null) | ||
if (_element is View && ElementGestureRecognizers is not null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we change this line to be:
if (_element is View && ElementGestureRecognizers is not null) | |
if (_element is View && ElementGestureRecognizers is ObservableCollection<IGestureRecognizer> gestures) |
And then use the local gestures
field throughout.
Calling ElementGestureRecognizers
multiple times, looks like it would do some work:
maui/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs
Lines 69 to 70 in ae20455
ObservableCollection<IGestureRecognizer>? ElementGestureRecognizers => | |
(_handler.VirtualView as Element)?.GetCompositeGestureRecognizers() as ObservableCollection<IGestureRecognizer>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used slightly different syntax to make the code more resilient to type changes (unlikely to occur I guess but anyway).
2547cfc
to
0e14cb3
Compare
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks ok to me,👍I triggered CI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some build errors here that need to be addressed
D:\a\1\s\src\Controls\src\Core\Platform\GestureManager\GesturePlatformManager.Windows.cs(294,61): error CS0128: A local variable or function named 'gestureRecognizers' is already defined in this scope [D:\a\1\s\src\Controls\src\Core\Controls.Core.csproj::TargetFramework=net8.0-windows10.0.20348.0]
D:\a\1\s\src\Controls\src\Core\Platform\GestureManager\GesturePlatformManager.Windows.cs(296,6): error CS0165: Use of unassigned local variable 'gestureRecognizers' [D:\a\1\s\src\Controls\src\Core\Controls.Core.csproj::TargetFramework=net8.0-windows10.0.20348.0]
C:\Users\VssAdministrator.nuget\packages\microsoft.windowsappsdk\1.5.240627000\buildTransitive\Microsoft.UI.Xaml.Markup.Compiler.interop.targets(841,9): error MSB3073: The command ""C:\Users\VssAdministrator.nuget\packages\microsoft.windowsappsdk\1.5.240627000\buildTransitive..\tools\net6.0..\net472\XamlCompiler.exe" "D:\a\1\s\artifacts\obj\Controls.Core\Release\net8.0-windows10.0.20348.0\input.json" "D:\a\1\s\artifacts\obj\Controls.Core\Release\net8.0-windows10.0.20348.0\output.json"" exited with code 1. [D:\a\1\s\src\Controls\src\Core\Controls.Core.csproj::TargetFramework=net8.0-windows10.0.20348.0]
D:\a\1\s\src\Controls\src\Core\Platform\GestureManager\GesturePlatformManager.Windows.cs(294,61): error CS0128: A local variable or function named 'gestureRecognizers' is already defined in this scope [D:\a\1\s\src\Controls\src\Core\Controls.Core.csproj::TargetFramework=net8.0-windows10.0.19041.0]
D:\a\1\s\src\Controls\src\Core\Platform\GestureManager\GesturePlatformManager.Windows.cs(296,6): error CS0165: Use of unassigned local variable 'gestureRecognizers' [D:\a\1\s\src\Controls\src\Core\Controls.Core.csproj::TargetFramework=net8.0-windows10.0.19041.0]
Azure Pipelines successfully started running 3 pipeline(s). |
Description of Change
The idea of the PR is that subscriptions of
_control.Tapped
_control.DoubleTapped
make sense to unsubscribe only if they were subscribed.
Performance impact
-> 86% for execution of
GestureManager.SetupGestureManager
Issues Fixed
Contributes to #21787
Easier to review with whitespace off.