-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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] Subscribe pointer events only when needed #23515
Merged
PureWeen
merged 2 commits into
dotnet:main
from
MartyIX:feature/2024-07-09-Optional-pointer-event-subscription
Jul 21, 2024
+25
−15
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -730,15 +730,7 @@ void PinchComplete(bool success) | |
|
||
void UpdateDragAndDropGestureRecognizers() | ||
{ | ||
if (_container is null) | ||
{ | ||
return; | ||
} | ||
|
||
var view = Element as View; | ||
IList<IGestureRecognizer>? gestures = view?.GestureRecognizers; | ||
|
||
if (gestures is null) | ||
if (_container is null || Element is not View view || view.GestureRecognizers is not IList<IGestureRecognizer> gestures) | ||
{ | ||
return; | ||
} | ||
|
@@ -812,16 +804,17 @@ void UpdatingGestureRecognizers() | |
} | ||
} | ||
|
||
_subscriptionFlags |= SubscriptionFlags.ContainerPgrPointerEventsSubscribed; | ||
_container.PointerEntered += OnPgrPointerEntered; | ||
_container.PointerExited += OnPgrPointerExited; | ||
_container.PointerMoved += OnPgrPointerMoved; | ||
_container.PointerPressed += OnPgrPointerPressed; | ||
_container.PointerReleased += OnPgrPointerReleased; | ||
bool hasPointerGesture = ElementGestureRecognizers.HasAnyGesturesFor<PointerGestureRecognizer>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed according to: #23515 (comment) |
||
|
||
if (hasPointerGesture) | ||
{ | ||
SubscribePointerEvents(_container); | ||
} | ||
|
||
bool hasSwipeGesture = gestures.HasAnyGesturesFor<SwipeGestureRecognizer>(); | ||
bool hasPinchGesture = gestures.HasAnyGesturesFor<PinchGestureRecognizer>(); | ||
bool hasPanGesture = gestures.HasAnyGesturesFor<PanGestureRecognizer>(); | ||
|
||
if (!hasSwipeGesture && !hasPinchGesture && !hasPanGesture) | ||
{ | ||
return; | ||
|
@@ -840,6 +833,12 @@ void UpdatingGestureRecognizers() | |
return; | ||
} | ||
|
||
// Pan, pinch, and swipe gestures need pointer events if not subscribed yet. | ||
if (!hasPointerGesture) | ||
{ | ||
SubscribePointerEvents(_container); | ||
} | ||
|
||
_subscriptionFlags |= SubscriptionFlags.ContainerManipulationAndPointerEventsSubscribed; | ||
_container.ManipulationMode = ManipulationModes.Scale | ManipulationModes.TranslateX | ManipulationModes.TranslateY; | ||
_container.ManipulationDelta += OnManipulationDelta; | ||
|
@@ -848,6 +847,17 @@ void UpdatingGestureRecognizers() | |
_container.PointerCanceled += OnPointerCanceled; | ||
} | ||
|
||
void SubscribePointerEvents(FrameworkElement container) | ||
{ | ||
_subscriptionFlags |= SubscriptionFlags.ContainerPgrPointerEventsSubscribed; | ||
|
||
container.PointerEntered += OnPgrPointerEntered; | ||
container.PointerExited += OnPgrPointerExited; | ||
container.PointerMoved += OnPgrPointerMoved; | ||
container.PointerPressed += OnPgrPointerPressed; | ||
container.PointerReleased += OnPgrPointerReleased; | ||
} | ||
|
||
void HandleTapped(object sender, TappedRoutedEventArgs tappedRoutedEventArgs) | ||
{ | ||
tappedRoutedEventArgs.Handled = true; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 a bit
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.
What about a simpler
if (ElementGestureRecognizers is not {} gestures) return;
?I think that
view.GestureRecognizer
is just wrong (not enough) in this situation.Or do you think we would have strange side effects?
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.
This is a different method. I don't want to change behavior here.
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.
Perhaps it can be done. I'm not sure. However, if I start with it - i.e. changing
IList<IGestureRecognizer>
toElementGestureRecognizers
- then nobody will want to review this PR and it will lead to delays.So I sort of prefer as little change as possible.
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.
For reference,
CompositeGesureRecognizers
is basically a proxy of theGestureRecognizers
with the addition of the pointer over gesture recognizer which is (un)set by this method here who checks the VSM for pointer over states.That said, and considering the only piece of code here caring about the pointer gesture recognizer is the one you changed, I feel this is a safe change.
Anyway I'll leave this to the MAUI team: my purpose is just to give more context information.