From 2cb2dca9d7961391d61965309055d2cfad2e05d1 Mon Sep 17 00:00:00 2001 From: MartyIX <203266+MartyIX@users.noreply.github.com> Date: Tue, 9 Jul 2024 22:40:19 +0200 Subject: [PATCH] Subscribe pointer events only when needed --- .../GesturePlatformManager.Windows.cs | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs b/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs index ba6d8a98f69c..d0cc70f7bb99 100644 --- a/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs +++ b/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs @@ -812,16 +812,18 @@ void UpdatingGestureRecognizers() } } - _subscriptionFlags |= SubscriptionFlags.ContainerPgrPointerEventsSubscribed; - _container.PointerEntered += OnPgrPointerEntered; - _container.PointerExited += OnPgrPointerExited; - _container.PointerMoved += OnPgrPointerMoved; - _container.PointerPressed += OnPgrPointerPressed; - _container.PointerReleased += OnPgrPointerReleased; + bool hasPointerGesture = gestures.HasAnyGesturesFor(); + + if (hasPointerGesture) + { + _subscriptionFlags |= SubscriptionFlags.ContainerPgrPointerEventsSubscribed; + SubscribePointerEvents(_container); + } bool hasSwipeGesture = gestures.HasAnyGesturesFor(); bool hasPinchGesture = gestures.HasAnyGesturesFor(); bool hasPanGesture = gestures.HasAnyGesturesFor(); + if (!hasSwipeGesture && !hasPinchGesture && !hasPanGesture) { return; @@ -840,6 +842,12 @@ void UpdatingGestureRecognizers() return; } + if (!hasPointerGesture) + { + _subscriptionFlags |= SubscriptionFlags.ContainerPgrPointerEventsSubscribed; + SubscribePointerEvents(_container); + } + _subscriptionFlags |= SubscriptionFlags.ContainerManipulationAndPointerEventsSubscribed; _container.ManipulationMode = ManipulationModes.Scale | ManipulationModes.TranslateX | ManipulationModes.TranslateY; _container.ManipulationDelta += OnManipulationDelta; @@ -848,6 +856,15 @@ void UpdatingGestureRecognizers() _container.PointerCanceled += OnPointerCanceled; } + void SubscribePointerEvents(FrameworkElement container) + { + container.PointerEntered += OnPgrPointerEntered; + container.PointerExited += OnPgrPointerExited; + container.PointerMoved += OnPgrPointerMoved; + container.PointerPressed += OnPgrPointerPressed; + container.PointerReleased += OnPgrPointerReleased; + } + void HandleTapped(object sender, TappedRoutedEventArgs tappedRoutedEventArgs) { tappedRoutedEventArgs.Handled = true;