Skip to content
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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just modernize a bit

Copy link
Contributor

@albyrock87 albyrock87 Jul 11, 2024

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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> to ElementGestureRecognizers - then nobody will want to review this PR and it will lead to delays.

So I sort of prefer as little change as possible.

Copy link
Contributor

@albyrock87 albyrock87 Jul 11, 2024

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 the GestureRecognizers 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.

{
return;
}
Expand Down Expand Up @@ -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>();
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Loading