Skip to content

Commit

Permalink
Reimplement by adding FirstGestureOrDefault
Browse files Browse the repository at this point in the history
  • Loading branch information
MartyIX committed Mar 26, 2024
1 parent edd66ef commit acadf48
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/Controls/src/Core/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,24 @@ public static IEnumerable<T> GetGesturesFor<T>(this IEnumerable<IGestureRecogniz
}

internal static bool HasAnyGesturesFor<T>(this IEnumerable<IGestureRecognizer>? gestures, Func<T, bool>? predicate = null) where T : GestureRecognizer
=> FirstGestureOrDefault(gestures, predicate) is not null;

internal static T? FirstGestureOrDefault<T>(this IEnumerable<IGestureRecognizer>? gestures, Func<T, bool>? predicate = null) where T : GestureRecognizer
{
if (gestures is null)
{
return false;
return null;
}

foreach (IGestureRecognizer item in gestures)
{
if (item is T gesture && (predicate is null || predicate(gesture)))
{
return true;
return gesture;
}
}

return false;
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -683,10 +683,10 @@ void UpdateDragAndDropGestureRecognizers()
return;
}

bool canDrag = gestures.GetGesturesFor<DragGestureRecognizer>().FirstOrDefault()?.CanDrag ?? false;
bool canDrag = gestures.FirstGestureOrDefault<DragGestureRecognizer>()?.CanDrag ?? false;
_container.CanDrag = canDrag;

bool allowDrop = gestures.GetGesturesFor<DropGestureRecognizer>().FirstOrDefault()?.AllowDrop ?? false;
bool allowDrop = gestures.FirstGestureOrDefault<DropGestureRecognizer>()?.AllowDrop ?? false;
_container.AllowDrop = allowDrop;

if (canDrag)
Expand Down

0 comments on commit acadf48

Please sign in to comment.