Skip to content

Commit

Permalink
fix(dragging): when a child and a parent subscribe to dragging, only …
Browse files Browse the repository at this point in the history
…fire on the child
  • Loading branch information
ramezgerges committed Nov 14, 2024
1 parent 453d1fe commit ccea9af
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
13 changes: 13 additions & 0 deletions src/Uno.UI/UI/Input/GestureRecognizer.Manipulation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,19 @@ private bool IsBeginningOfDragManipulation()
}
}

public void DisableDragging()
{
StopDragTimer();
if (_state is ManipulationState.Starting)
{
_isDraggingEnable = false;
}
else if (_state is ManipulationState.Started && IsDragManipulation)
{
Complete();
}
}

private bool ShouldStartInertia(ManipulationVelocities velocities)
=> _inertia is null
&& !IsDragManipulation
Expand Down
13 changes: 8 additions & 5 deletions src/Uno.UI/UI/Input/GestureRecognizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,19 @@ public void CompleteGesture()
}

/// <returns>The set of events that can be raised by this recognizer for this pointer ID</returns>
internal GestureSettings PreventEvents(uint pointerId, GestureSettings events)
internal GestureSettings PreventEvents(PointerIdentifier pointerId, GestureSettings events)
{
if (_gestures.TryGetValue(pointerId, out var gesture))
if (_gestures.TryGetValue(pointerId.Id, out var gesture))
{
gesture.PreventGestures(events & GestureSettingsHelper.SupportedGestures);
gesture.PreventGestures(events);
}

return gesture.Settings;
if ((events & GestureSettings.Drag) != 0 && (_manipulation?.IsActive(pointerId) ?? false))
{
_manipulation?.DisableDragging();
}

return GestureSettings.None;
return _gestureSettings;
}

#region Manipulations
Expand Down
24 changes: 19 additions & 5 deletions src/Uno.UI/UI/Xaml/UIElement.Pointers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Windows.ApplicationModel.DataTransfer.DragDrop;
using Windows.ApplicationModel.DataTransfer.DragDrop.Core;
using Windows.Devices.Haptics;
using Windows.Devices.Input;
using Windows.Foundation;
using Windows.UI.Core;
using Microsoft.UI.Xaml.Input;
Expand All @@ -22,6 +23,7 @@
using Uno.UI.Extensions;
using Uno.UI.Xaml;
using Uno.UI.Xaml.Core;
using PointerDeviceType = Windows.Devices.Input.PointerDeviceType;

#if HAS_UNO_WINUI
using Microsoft.UI.Input;
Expand Down Expand Up @@ -558,19 +560,31 @@ partial void PrepareManagedGestureEventBubbling(RoutedEvent routedEvent, ref Rou
{
if (routedEvent == TappedEvent)
{
GestureRecognizer.PreventEvents(((TappedRoutedEventArgs)args).PointerId, GestureSettings.Tap);
var tappedArgs = (TappedRoutedEventArgs)args;
GestureRecognizer.PreventEvents(
new PointerIdentifier((PointerDeviceType)tappedArgs.PointerDeviceType, tappedArgs.PointerId),
GestureSettings.Tap);
}
else if (routedEvent == DoubleTappedEvent)
{
GestureRecognizer.PreventEvents(((DoubleTappedRoutedEventArgs)args).PointerId, GestureSettings.DoubleTap);
var doubleTappedArgs = (DoubleTappedRoutedEventArgs)args;
GestureRecognizer.PreventEvents(
new PointerIdentifier((PointerDeviceType)doubleTappedArgs.PointerDeviceType, doubleTappedArgs.PointerId),
GestureSettings.DoubleTap);
}
else if (routedEvent == RightTappedEvent)
{
GestureRecognizer.PreventEvents(((RightTappedRoutedEventArgs)args).PointerId, GestureSettings.RightTap);
var rightTappedArgs = (RightTappedRoutedEventArgs)args;
GestureRecognizer.PreventEvents(
new PointerIdentifier((PointerDeviceType)rightTappedArgs.PointerDeviceType, rightTappedArgs.PointerId),
GestureSettings.RightTap);
}
else if (routedEvent == HoldingEvent)
{
GestureRecognizer.PreventEvents(((HoldingRoutedEventArgs)args).PointerId, GestureSettings.Hold);
var holdingArgs = (HoldingRoutedEventArgs)args;
GestureRecognizer.PreventEvents(
new PointerIdentifier((PointerDeviceType)holdingArgs.PointerDeviceType, holdingArgs.PointerId),
GestureSettings.Hold);
}
}
}
Expand Down Expand Up @@ -606,7 +620,7 @@ private void UpdateRaisedGestureEventsFlag(PointerRoutedEventArgs args)
}

var pointerId = args.Pointer.PointerId;
args.GestureEventsAlreadyRaised |= GestureRecognizer.PreventEvents(pointerId, args.GestureEventsAlreadyRaised);
args.GestureEventsAlreadyRaised |= GestureRecognizer.PreventEvents(new PointerIdentifier((PointerDeviceType)args.Pointer.PointerDeviceType, args.Pointer.PointerId), args.GestureEventsAlreadyRaised);
}
#endregion

Expand Down

0 comments on commit ccea9af

Please sign in to comment.