From acabea4bc9ade8b57f3f88e877ed7e96ad5f996c Mon Sep 17 00:00:00 2001 From: MartyIX <203266+MartyIX@users.noreply.github.com> Date: Tue, 26 Mar 2024 09:23:17 +0100 Subject: [PATCH 1/7] `EnumerableExtensions`: Enable nullable --- src/Controls/src/Core/EnumerableExtensions.cs | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/Controls/src/Core/EnumerableExtensions.cs b/src/Controls/src/Core/EnumerableExtensions.cs index e9c16b6b789b..655b9f409a0f 100644 --- a/src/Controls/src/Core/EnumerableExtensions.cs +++ b/src/Controls/src/Core/EnumerableExtensions.cs @@ -1,18 +1,16 @@ -#nullable disable using System; using System.Collections.Generic; -using System.ComponentModel; namespace Microsoft.Maui.Controls.Internals { static class EnumerableExtensions { - public static bool HasChildGesturesFor(this IEnumerable elements, Func predicate = null) where T : GestureRecognizer + public static bool HasChildGesturesFor(this IEnumerable? elements, Func? predicate = null) where T : GestureRecognizer { - if (elements == null) + if (elements is null) return false; - if (predicate == null) + if (predicate is null) predicate = x => true; foreach (var element in elements) @@ -26,12 +24,12 @@ public static bool HasChildGesturesFor(this IEnumerable eleme return false; } - public static IEnumerable GetChildGesturesFor(this IEnumerable elements, Func predicate = null) where T : GestureRecognizer + public static IEnumerable GetChildGesturesFor(this IEnumerable? elements, Func? predicate = null) where T : GestureRecognizer { - if (elements == null) + if (elements is null) yield break; - if (predicate == null) + if (predicate is null) predicate = x => true; foreach (var element in elements) @@ -43,12 +41,12 @@ public static IEnumerable GetChildGesturesFor(this IEnumerable GetGesturesFor(this IEnumerable gestures, Func predicate = null) where T : GestureRecognizer + public static IEnumerable GetGesturesFor(this IEnumerable? gestures, Func? predicate = null) where T : GestureRecognizer { - if (gestures == null) + if (gestures is null) yield break; - if (predicate == null) + if (predicate is null) predicate = x => true; foreach (IGestureRecognizer item in new List(gestures)) From 19d7b6970e00f01878bfea5825f7a9930ead2a35 Mon Sep 17 00:00:00 2001 From: MartyIX <203266+MartyIX@users.noreply.github.com> Date: Tue, 26 Mar 2024 11:21:44 +0100 Subject: [PATCH 2/7] Add `EnumerableExtensions.HasAnyGesturesFor` --- src/Controls/src/Core/EnumerableExtensions.cs | 21 ++++++++++++ .../GesturePlatformManager.Windows.cs | 32 +++++++++++-------- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/src/Controls/src/Core/EnumerableExtensions.cs b/src/Controls/src/Core/EnumerableExtensions.cs index 655b9f409a0f..79a7af38cf5e 100644 --- a/src/Controls/src/Core/EnumerableExtensions.cs +++ b/src/Controls/src/Core/EnumerableExtensions.cs @@ -41,6 +41,7 @@ public static IEnumerable GetChildGesturesFor(this IEnumerableThe method makes a defensive copy of the gestures. public static IEnumerable GetGesturesFor(this IEnumerable? gestures, Func? predicate = null) where T : GestureRecognizer { if (gestures is null) @@ -58,5 +59,25 @@ public static IEnumerable GetGesturesFor(this IEnumerable(this IEnumerable? gestures, Func? predicate = null) where T : GestureRecognizer + { + if (gestures is null) + { + return false; + } + + predicate ??= x => true; + + foreach (IGestureRecognizer item in gestures) + { + if (item is T gesture && predicate(gesture)) + { + return true; + } + } + + return false; + } } } diff --git a/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs b/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs index 939d240462b1..58f1880c46ff 100644 --- a/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs +++ b/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs @@ -670,28 +670,32 @@ void PinchComplete(bool success) void UpdateDragAndDropGestureRecognizers() { - if (_container == null) + if (_container is null) + { return; + } var view = Element as View; IList? gestures = view?.GestureRecognizers; - if (gestures == null) + if (gestures is null) + { return; + } - _container.CanDrag = gestures.GetGesturesFor() - .FirstOrDefault()?.CanDrag ?? false; + bool canDrag = gestures.GetGesturesFor().FirstOrDefault()?.CanDrag ?? false; + _container.CanDrag = canDrag; - _container.AllowDrop = gestures.GetGesturesFor() - .FirstOrDefault()?.AllowDrop ?? false; + bool allowDrop = gestures.GetGesturesFor().FirstOrDefault()?.AllowDrop ?? false; + _container.AllowDrop = allowDrop; - if (_container.CanDrag) + if (canDrag) { _container.DragStarting += HandleDragStarting; _container.DropCompleted += HandleDropCompleted; } - if (_container.AllowDrop) + if (allowDrop) { _container.DragOver += HandleDragOver; _container.Drop += HandleDrop; @@ -714,7 +718,7 @@ void UpdatingGestureRecognizers() IList? childGestures = children?.GetChildGesturesFor().ToList(); - if (gestures.GetGesturesFor(g => g.NumberOfTapsRequired == 1).Any() + if (gestures.HasAnyGesturesFor(g => g.NumberOfTapsRequired == 1) || children?.GetChildGesturesFor(g => g.NumberOfTapsRequired == 1).Any() == true) { _container.Tapped += OnTap; @@ -728,7 +732,7 @@ void UpdatingGestureRecognizers() } } - if (gestures.GetGesturesFor(g => g.NumberOfTapsRequired == 1 || g.NumberOfTapsRequired == 2).Any() + if (gestures.HasAnyGesturesFor(g => g.NumberOfTapsRequired == 1 || g.NumberOfTapsRequired == 2) || children?.GetChildGesturesFor(g => g.NumberOfTapsRequired == 1 || g.NumberOfTapsRequired == 2).Any() == true) { _container.DoubleTapped += OnTap; @@ -747,11 +751,13 @@ void UpdatingGestureRecognizers() _container.PointerPressed += OnPgrPointerPressed; _container.PointerReleased += OnPgrPointerReleased; - bool hasSwipeGesture = gestures.GetGesturesFor().GetEnumerator().MoveNext(); - bool hasPinchGesture = gestures.GetGesturesFor().GetEnumerator().MoveNext(); - bool hasPanGesture = gestures.GetGesturesFor().GetEnumerator().MoveNext(); + bool hasSwipeGesture = gestures.HasAnyGesturesFor(); + bool hasPinchGesture = gestures.HasAnyGesturesFor(); + bool hasPanGesture = gestures.HasAnyGesturesFor(); if (!hasSwipeGesture && !hasPinchGesture && !hasPanGesture) + { return; + } //We can't handle ManipulationMode.Scale and System , so we don't support pinch/pan on a scrollview if (Element is ScrollView) From e984695ee8a4e59c63bbb1d2b7b0e8a75a287292 Mon Sep 17 00:00:00 2001 From: MartyIX <203266+MartyIX@users.noreply.github.com> Date: Tue, 26 Mar 2024 11:22:57 +0100 Subject: [PATCH 3/7] Sandbox measure code --- .../Controls.Sample.Sandbox/MainPage.xaml | 5654 +++++++++++++++++ .../Controls.Sample.Sandbox/MainPage.xaml.cs | 5 + .../Controls.Sample.Sandbox/MauiProgram.cs | 2 +- 3 files changed, 5660 insertions(+), 1 deletion(-) diff --git a/src/Controls/samples/Controls.Sample.Sandbox/MainPage.xaml b/src/Controls/samples/Controls.Sample.Sandbox/MainPage.xaml index e1762ab92d18..8ad3224799b8 100644 --- a/src/Controls/samples/Controls.Sample.Sandbox/MainPage.xaml +++ b/src/Controls/samples/Controls.Sample.Sandbox/MainPage.xaml @@ -3,4 +3,5658 @@ xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Maui.Controls.Sample.MainPage" xmlns:local="clr-namespace:Maui.Controls.Sample"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Controls/samples/Controls.Sample.Sandbox/MainPage.xaml.cs b/src/Controls/samples/Controls.Sample.Sandbox/MainPage.xaml.cs index effdbcdb46d7..324f8ea31794 100644 --- a/src/Controls/samples/Controls.Sample.Sandbox/MainPage.xaml.cs +++ b/src/Controls/samples/Controls.Sample.Sandbox/MainPage.xaml.cs @@ -14,5 +14,10 @@ public MainPage() { InitializeComponent(); } + + private void DragGestureRecognizer_DragStarting(object sender, DragStartingEventArgs e) + { + + } } } \ No newline at end of file diff --git a/src/Controls/samples/Controls.Sample.Sandbox/MauiProgram.cs b/src/Controls/samples/Controls.Sample.Sandbox/MauiProgram.cs index c4082431bc46..126ea287c858 100644 --- a/src/Controls/samples/Controls.Sample.Sandbox/MauiProgram.cs +++ b/src/Controls/samples/Controls.Sample.Sandbox/MauiProgram.cs @@ -10,7 +10,7 @@ public static class MauiProgram public static MauiApp CreateMauiApp() => MauiApp .CreateBuilder() - .UseMauiMaps() + //.UseMauiMaps() .UseMauiApp() .Build(); } From 1b3612b63ab8930909587785deb9123c57d841c6 Mon Sep 17 00:00:00 2001 From: MartyIX <203266+MartyIX@users.noreply.github.com> Date: Tue, 26 Mar 2024 11:23:01 +0100 Subject: [PATCH 4/7] Revert "Sandbox measure code" This reverts commit e984695ee8a4e59c63bbb1d2b7b0e8a75a287292. --- .../Controls.Sample.Sandbox/MainPage.xaml | 5654 ----------------- .../Controls.Sample.Sandbox/MainPage.xaml.cs | 5 - .../Controls.Sample.Sandbox/MauiProgram.cs | 2 +- 3 files changed, 1 insertion(+), 5660 deletions(-) diff --git a/src/Controls/samples/Controls.Sample.Sandbox/MainPage.xaml b/src/Controls/samples/Controls.Sample.Sandbox/MainPage.xaml index 8ad3224799b8..e1762ab92d18 100644 --- a/src/Controls/samples/Controls.Sample.Sandbox/MainPage.xaml +++ b/src/Controls/samples/Controls.Sample.Sandbox/MainPage.xaml @@ -3,5658 +3,4 @@ xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Maui.Controls.Sample.MainPage" xmlns:local="clr-namespace:Maui.Controls.Sample"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Controls/samples/Controls.Sample.Sandbox/MainPage.xaml.cs b/src/Controls/samples/Controls.Sample.Sandbox/MainPage.xaml.cs index 324f8ea31794..effdbcdb46d7 100644 --- a/src/Controls/samples/Controls.Sample.Sandbox/MainPage.xaml.cs +++ b/src/Controls/samples/Controls.Sample.Sandbox/MainPage.xaml.cs @@ -14,10 +14,5 @@ public MainPage() { InitializeComponent(); } - - private void DragGestureRecognizer_DragStarting(object sender, DragStartingEventArgs e) - { - - } } } \ No newline at end of file diff --git a/src/Controls/samples/Controls.Sample.Sandbox/MauiProgram.cs b/src/Controls/samples/Controls.Sample.Sandbox/MauiProgram.cs index 126ea287c858..c4082431bc46 100644 --- a/src/Controls/samples/Controls.Sample.Sandbox/MauiProgram.cs +++ b/src/Controls/samples/Controls.Sample.Sandbox/MauiProgram.cs @@ -10,7 +10,7 @@ public static class MauiProgram public static MauiApp CreateMauiApp() => MauiApp .CreateBuilder() - //.UseMauiMaps() + .UseMauiMaps() .UseMauiApp() .Build(); } From 39b7ec6301de1c56cd624344d8e9ab49f4837490 Mon Sep 17 00:00:00 2001 From: MartyIX <203266+MartyIX@users.noreply.github.com> Date: Tue, 26 Mar 2024 19:37:50 +0100 Subject: [PATCH 5/7] Do not create lambdas + apply MSVS suggestion regarding pattern matching + add braces --- src/Controls/src/Core/EnumerableExtensions.cs | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Controls/src/Core/EnumerableExtensions.cs b/src/Controls/src/Core/EnumerableExtensions.cs index 79a7af38cf5e..27dd0118218e 100644 --- a/src/Controls/src/Core/EnumerableExtensions.cs +++ b/src/Controls/src/Core/EnumerableExtensions.cs @@ -8,18 +8,20 @@ static class EnumerableExtensions public static bool HasChildGesturesFor(this IEnumerable? elements, Func? predicate = null) where T : GestureRecognizer { if (elements is null) + { return false; - - if (predicate is null) - predicate = x => true; + } foreach (var element in elements) + { foreach (var item in element.GestureRecognizers) { - var gesture = item as T; - if (gesture != null && predicate(gesture)) + if (item is T gesture && (predicate is null || predicate(gesture))) + { return true; + } } + } return false; } @@ -27,33 +29,33 @@ public static bool HasChildGesturesFor(this IEnumerable? elem public static IEnumerable GetChildGesturesFor(this IEnumerable? elements, Func? predicate = null) where T : GestureRecognizer { if (elements is null) + { yield break; - - if (predicate is null) - predicate = x => true; + } foreach (var element in elements) + { foreach (var item in element.GestureRecognizers) { - var gesture = item as T; - if (gesture != null && predicate(gesture)) + if (item is T gesture && (predicate is null || predicate(gesture))) + { yield return gesture; + } } + } } /// The method makes a defensive copy of the gestures. public static IEnumerable GetGesturesFor(this IEnumerable? gestures, Func? predicate = null) where T : GestureRecognizer { if (gestures is null) + { yield break; - - if (predicate is null) - predicate = x => true; + } foreach (IGestureRecognizer item in new List(gestures)) { - var gesture = item as T; - if (gesture != null && predicate(gesture)) + if (item is T gesture && (predicate is null || predicate(gesture))) { yield return gesture; } @@ -67,11 +69,9 @@ public static bool HasAnyGesturesFor(this IEnumerable? ge return false; } - predicate ??= x => true; - foreach (IGestureRecognizer item in gestures) { - if (item is T gesture && predicate(gesture)) + if (item is T gesture && (predicate is null || predicate(gesture))) { return true; } From edd66ef593bc013c18ccddeb493a90a985f1fd05 Mon Sep 17 00:00:00 2001 From: MartyIX <203266+MartyIX@users.noreply.github.com> Date: Tue, 26 Mar 2024 19:40:17 +0100 Subject: [PATCH 6/7] Make `HasAnyGesturesFor` `internal` --- src/Controls/src/Core/EnumerableExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controls/src/Core/EnumerableExtensions.cs b/src/Controls/src/Core/EnumerableExtensions.cs index 27dd0118218e..19e0f90b803d 100644 --- a/src/Controls/src/Core/EnumerableExtensions.cs +++ b/src/Controls/src/Core/EnumerableExtensions.cs @@ -62,7 +62,7 @@ public static IEnumerable GetGesturesFor(this IEnumerable(this IEnumerable? gestures, Func? predicate = null) where T : GestureRecognizer + internal static bool HasAnyGesturesFor(this IEnumerable? gestures, Func? predicate = null) where T : GestureRecognizer { if (gestures is null) { From acadf48a46b5b7b9c1daa67513787bad05b330cb Mon Sep 17 00:00:00 2001 From: MartyIX <203266+MartyIX@users.noreply.github.com> Date: Tue, 26 Mar 2024 19:54:20 +0100 Subject: [PATCH 7/7] Reimplement by adding `FirstGestureOrDefault` --- src/Controls/src/Core/EnumerableExtensions.cs | 9 ++++++--- .../GestureManager/GesturePlatformManager.Windows.cs | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Controls/src/Core/EnumerableExtensions.cs b/src/Controls/src/Core/EnumerableExtensions.cs index 19e0f90b803d..d2915b59a6c3 100644 --- a/src/Controls/src/Core/EnumerableExtensions.cs +++ b/src/Controls/src/Core/EnumerableExtensions.cs @@ -63,21 +63,24 @@ public static IEnumerable GetGesturesFor(this IEnumerable(this IEnumerable? gestures, Func? predicate = null) where T : GestureRecognizer + => FirstGestureOrDefault(gestures, predicate) is not null; + + internal static T? FirstGestureOrDefault(this IEnumerable? gestures, Func? 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; } } } diff --git a/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs b/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs index 58f1880c46ff..a59ff797e33a 100644 --- a/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs +++ b/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs @@ -683,10 +683,10 @@ void UpdateDragAndDropGestureRecognizers() return; } - bool canDrag = gestures.GetGesturesFor().FirstOrDefault()?.CanDrag ?? false; + bool canDrag = gestures.FirstGestureOrDefault()?.CanDrag ?? false; _container.CanDrag = canDrag; - bool allowDrop = gestures.GetGesturesFor().FirstOrDefault()?.AllowDrop ?? false; + bool allowDrop = gestures.FirstGestureOrDefault()?.AllowDrop ?? false; _container.AllowDrop = allowDrop; if (canDrag)