-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Proposal - Replace internal use of MessagingCenter #3880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
de967b9
39867d8
6cb67bb
4a01020
c4e8f49
63a4020
b425af7
ca9f0d7
b5125da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
| using CommunityToolkit.Mvvm.Messaging; | ||
| using CoreGraphics; | ||
| using Foundation; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
@@ -655,30 +656,43 @@ internal static string ResolveMsAppDataUri(Uri uri) | |
| internal void SubscribeToAlertsAndActionSheets() | ||
| { | ||
| var busyCount = 0; | ||
| MessagingCenter.Subscribe(this, Page.BusySetSignalName, (Page sender, bool enabled) => | ||
|
|
||
| WeakReferenceMessenger.Default.Register<Platform, PageBusyMessage>(this, (platform, message) => | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is introducing a closure to capture |
||
| { | ||
| var sender = message.Page; | ||
| var enabled = message.IsBusy; | ||
|
|
||
| if (!PageIsChildOfPlatform(sender)) | ||
| return; | ||
| busyCount = Math.Max(0, enabled ? busyCount + 1 : busyCount - 1); | ||
| UIApplication.SharedApplication.NetworkActivityIndicatorVisible = busyCount > 0; | ||
| }); | ||
|
|
||
| MessagingCenter.Subscribe(this, Page.AlertSignalName, (Page sender, AlertArguments arguments) => | ||
| WeakReferenceMessenger.Default.Register<Platform, PageAlertMessage>(this, (platform, message) => | ||
| { | ||
| var sender = message.Page; | ||
| var arguments = message.Arguments; | ||
|
|
||
| if (!PageIsChildOfPlatform(sender)) | ||
| return; | ||
| PresentAlert(arguments); | ||
| }); | ||
|
|
||
| MessagingCenter.Subscribe(this, Page.PromptSignalName, (Page sender, PromptArguments arguments) => | ||
| WeakReferenceMessenger.Default.Register<Platform, PromptMessage>(this, (platform, message) => | ||
| { | ||
| var sender = message.Page; | ||
| var arguments = message.Arguments; | ||
|
|
||
| if (!PageIsChildOfPlatform(sender)) | ||
| return; | ||
| PresentPrompt(arguments); | ||
| }); | ||
|
|
||
| MessagingCenter.Subscribe(this, Page.ActionSheetSignalName, (Page sender, ActionSheetArguments arguments) => | ||
| WeakReferenceMessenger.Default.Register<Platform, ActionSheetMessage>(this, (platform, message) => | ||
| { | ||
| var sender = message.Page; | ||
| var arguments = message.Arguments; | ||
|
|
||
| if (!PageIsChildOfPlatform(sender)) | ||
| return; | ||
|
|
||
|
|
@@ -695,10 +709,6 @@ static bool IsModalPresentedFullScreen(Page modal) | |
|
|
||
| internal void UnsubscribeFromAlertsAndActionsSheets() | ||
| { | ||
| MessagingCenter.Unsubscribe<Page, ActionSheetArguments>(this, Page.ActionSheetSignalName); | ||
| MessagingCenter.Unsubscribe<Page, AlertArguments>(this, Page.AlertSignalName); | ||
| MessagingCenter.Unsubscribe<Page, PromptArguments>(this, Page.PromptSignalName); | ||
| MessagingCenter.Unsubscribe<Page, bool>(this, Page.BusySetSignalName); | ||
| } | ||
|
|
||
| internal void MarkForRemoval() | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |||||
| using Microsoft.Maui.Graphics; | ||||||
| using ObjCRuntime; | ||||||
| using UIKit; | ||||||
| using CommunityToolkit.Mvvm.Messaging; | ||||||
|
|
||||||
| namespace Microsoft.Maui.Controls.Compatibility.Platform.iOS | ||||||
| { | ||||||
|
|
@@ -391,7 +392,8 @@ public override void WillRotate(UIInterfaceOrientation toInterfaceOrientation, d | |||||
| } | ||||||
|
|
||||||
| FlyoutPage.UpdateFlyoutLayoutBehavior(); | ||||||
| MessagingCenter.Send<IVisualElementRenderer>(this, NavigationRenderer.UpdateToolbarButtons); | ||||||
|
|
||||||
| WeakReferenceMessenger.Default.Send(new UpdateToolBarButtonsMessage()); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: this can be simplified:
Suggested change
Same for the other two occurrences below in this file. |
||||||
| } | ||||||
|
|
||||||
| base.WillRotate(toInterfaceOrientation, duration); | ||||||
|
|
@@ -449,7 +451,7 @@ void ClearControllers() | |||||
| void HandleFlyoutPropertyChanged(object sender, PropertyChangedEventArgs e) | ||||||
| { | ||||||
| if (e.PropertyName == Page.IconImageSourceProperty.PropertyName || e.PropertyName == Page.TitleProperty.PropertyName) | ||||||
| MessagingCenter.Send<IVisualElementRenderer>(this, NavigationRenderer.UpdateToolbarButtons); | ||||||
| WeakReferenceMessenger.Default.Send(new UpdateToolBarButtonsMessage()); | ||||||
| } | ||||||
|
|
||||||
| void HandlePropertyChanged(object sender, PropertyChangedEventArgs e) | ||||||
|
|
@@ -470,7 +472,7 @@ void HandlePropertyChanged(object sender, PropertyChangedEventArgs e) | |||||
| else if (e.Is(Microsoft.Maui.Controls.FlyoutPage.FlyoutLayoutBehaviorProperty)) | ||||||
| UpdateFlyoutLayoutBehavior(base.View.Bounds.Size); | ||||||
|
|
||||||
| MessagingCenter.Send<IVisualElementRenderer>(this, NavigationRenderer.UpdateToolbarButtons); | ||||||
| WeakReferenceMessenger.Default.Send(new UpdateToolBarButtonsMessage()); | ||||||
| } | ||||||
|
|
||||||
| public override void ViewWillTransitionToSize(CGSize toSize, IUIViewControllerTransitionCoordinator coordinator) | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: this could be simplied through the extension: