Skip to content

Commit b18db8b

Browse files
Expose DispatcherExtensions so it could be used outside of Maui as well (#30488)
* updated code changes * Added UnitTest * added testcases * resolved build errors. * Update PublicAPI.Unshipped.txt * Update DispatcherExtensions.cs
1 parent 0e6de6c commit b18db8b

File tree

21 files changed

+338
-41
lines changed

21 files changed

+338
-41
lines changed

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

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

67
namespace Microsoft.Maui.Controls.Compatibility.Platform.Android
78
{

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

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

56
namespace Microsoft.Maui.Controls.Compatibility.Platform.Android
67
{

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
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;
2829

2930
namespace Microsoft.Maui.Controls.Compatibility.Platform.UWP
3031
{

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

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

1011
#if __MOBILE__
1112
using ObjCRuntime;

src/Controls/src/Core/AppThemeBinding.cs

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

78
namespace Microsoft.Maui.Controls
89
{

src/Controls/src/Core/BindingExpression.cs

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

1415
namespace Microsoft.Maui.Controls
1516
{

src/Controls/src/Core/DispatcherExtensions.cs

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

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-
9049
static IDispatcher EnsureDispatcher(IDispatcher? dispatcher)
9150
{
9251
if (dispatcher is not null)

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

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

78
namespace Microsoft.Maui.Controls.Handlers.Items
89
{

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

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

67
namespace Microsoft.Maui.Controls.Handlers.Items
78
{

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

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

78
namespace Microsoft.Maui.Controls.Platform
89
{

0 commit comments

Comments
 (0)