Skip to content

Commit 93923d7

Browse files
authored
Revert "Expose DispatcherExtensions so it could be used outside of Maui as well" (#31184)
Reverts #30488 Fixes #31139
2 parents 8025b56 + b39dd70 commit 93923d7

21 files changed

Lines changed: 41 additions & 338 deletions

File tree

src/Compatibility/Core/src/Android/CollectionView/ObservableGroupedSource.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.Collections.Specialized;
5-
using Microsoft.Maui.Dispatching;
65

76
namespace Microsoft.Maui.Controls.Compatibility.Platform.Android
87
{

src/Compatibility/Core/src/Android/CollectionView/ObservableItemsSource.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections;
33
using System.Collections.Specialized;
4-
using Microsoft.Maui.Dispatching;
54

65
namespace Microsoft.Maui.Controls.Compatibility.Platform.Android
76
{

src/Compatibility/Core/src/Windows/ListViewRenderer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
using WListView = Microsoft.UI.Xaml.Controls.ListView;
2626
using WRect = Windows.Foundation.Rect;
2727
using WSelectionChangedEventArgs = Microsoft.UI.Xaml.Controls.SelectionChangedEventArgs;
28-
using Microsoft.Maui.Dispatching;
2928

3029
namespace Microsoft.Maui.Controls.Compatibility.Platform.UWP
3130
{

src/Compatibility/Core/src/iOS/VisualElementTracker.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using Microsoft.Maui.Controls.Internals;
77
using Microsoft.Maui.Controls.Platform;
88
using Microsoft.Maui.Graphics;
9-
using Microsoft.Maui.Dispatching;
109

1110
#if __MOBILE__
1211
using ObjCRuntime;

src/Controls/src/Core/AppThemeBinding.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using Microsoft.Maui.ApplicationModel;
44
using Microsoft.Maui.Controls.Internals;
55
using Microsoft.Maui.Controls.Xaml.Diagnostics;
6-
using Microsoft.Maui.Dispatching;
76

87
namespace Microsoft.Maui.Controls
98
{

src/Controls/src/Core/BindingExpression.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using System.Runtime.CompilerServices;
1111
using Microsoft.Maui.Controls.Internals;
1212
using Microsoft.Maui.Controls.Xaml.Diagnostics;
13-
using Microsoft.Maui.Dispatching;
1413

1514
namespace Microsoft.Maui.Controls
1615
{

src/Controls/src/Core/DispatcherExtensions.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Threading.Tasks;
23
using Microsoft.Extensions.DependencyInjection;
34
using Microsoft.Maui.Dispatching;
45
using Microsoft.Maui.Hosting;
@@ -46,6 +47,46 @@ bindableObject is Element element &&
4647
throw new InvalidOperationException("BindableObject was not instantiated on a thread with a dispatcher nor does the current application have a dispatcher.");
4748
}
4849

50+
public static void DispatchIfRequired(this IDispatcher? dispatcher, Action action)
51+
{
52+
dispatcher = EnsureDispatcher(dispatcher);
53+
if (dispatcher.IsDispatchRequired)
54+
{
55+
dispatcher.Dispatch(action);
56+
}
57+
else
58+
{
59+
action();
60+
}
61+
}
62+
63+
public static Task DispatchIfRequiredAsync(this IDispatcher? dispatcher, Action action)
64+
{
65+
dispatcher = EnsureDispatcher(dispatcher);
66+
if (dispatcher.IsDispatchRequired)
67+
{
68+
return dispatcher.DispatchAsync(action);
69+
}
70+
else
71+
{
72+
action();
73+
return Task.CompletedTask;
74+
}
75+
}
76+
77+
public static Task DispatchIfRequiredAsync(this IDispatcher? dispatcher, Func<Task> action)
78+
{
79+
dispatcher = EnsureDispatcher(dispatcher);
80+
if (dispatcher.IsDispatchRequired)
81+
{
82+
return dispatcher.DispatchAsync(action);
83+
}
84+
else
85+
{
86+
return action();
87+
}
88+
}
89+
4990
static IDispatcher EnsureDispatcher(IDispatcher? dispatcher)
5091
{
5192
if (dispatcher is not null)

src/Controls/src/Core/Handlers/Items/Android/ItemsSources/ObservableGroupedSource.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Collections;
44
using System.Collections.Generic;
55
using System.Collections.Specialized;
6-
using Microsoft.Maui.Dispatching;
76

87
namespace Microsoft.Maui.Controls.Handlers.Items
98
{

src/Controls/src/Core/Handlers/Items/Android/ItemsSources/ObservableItemsSource.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System;
33
using System.Collections;
44
using System.Collections.Specialized;
5-
using Microsoft.Maui.Dispatching;
65

76
namespace Microsoft.Maui.Controls.Handlers.Items
87
{

src/Controls/src/Core/Platform/Windows/CollectionView/GroupedItemTemplateCollection.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Collections;
44
using System.Collections.ObjectModel;
55
using System.Collections.Specialized;
6-
using Microsoft.Maui.Dispatching;
76

87
namespace Microsoft.Maui.Controls.Platform
98
{

0 commit comments

Comments
 (0)