Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 10 additions & 22 deletions src/Controls/src/Core/Page/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,10 @@ public Task<string> DisplayActionSheet(string title, string cancel, string destr
var args = new ActionSheetArguments(title, cancel, destruction, buttons);

args.FlowDirection = flowDirection;
#pragma warning disable CS0618 // TODO: Remove when we internalize/replace MessagingCenter
if (IsPlatformEnabled)
MessagingCenter.Send(this, ActionSheetSignalName, args);
Window.AlertManager.RequestActionSheet(this, args);
else
_pendingActions.Add(() => MessagingCenter.Send(this, ActionSheetSignalName, args));
#pragma warning restore CS0618 // Type or member is obsolete
_pendingActions.Add(() => Window.AlertManager.RequestActionSheet(this, args));

return args.Result.Task;
}
Expand Down Expand Up @@ -339,12 +337,10 @@ public Task<bool> DisplayAlert(string title, string message, string accept, stri
var args = new AlertArguments(title, message, accept, cancel);
args.FlowDirection = flowDirection;

#pragma warning disable CS0618 // TODO: Remove when we internalize/replace MessagingCenter
if (IsPlatformEnabled)
MessagingCenter.Send(this, AlertSignalName, args);
Window.AlertManager.RequestAlert(this, args);
else
_pendingActions.Add(() => MessagingCenter.Send(this, AlertSignalName, args));
#pragma warning restore CS0618 // Type or member is obsolete
_pendingActions.Add(() => Window.AlertManager.RequestAlert(this, args));

return args.Result.Task;
}
Expand All @@ -365,12 +361,10 @@ public Task<bool> DisplayAlert(string title, string message, string accept, stri
{
var args = new PromptArguments(title, message, accept, cancel, placeholder, maxLength, keyboard, initialValue);

#pragma warning disable CS0618 // TODO: Remove when we internalize/replace MessagingCenter
if (IsPlatformEnabled)
MessagingCenter.Send(this, PromptSignalName, args);
Window.AlertManager.RequestPrompt(this, args);
else
_pendingActions.Add(() => MessagingCenter.Send(this, PromptSignalName, args));
#pragma warning restore CS0618 // Type or member is obsolete
_pendingActions.Add(() => Window.AlertManager.RequestPrompt(this, args));

return args.Result.Task;
}
Expand Down Expand Up @@ -648,13 +642,11 @@ public void SendAppearing()

if (IsBusy)
{
#pragma warning disable CS0618 // TODO: Remove when we internalize/replace MessagingCenter
if (IsPlatformEnabled)
MessagingCenter.Send(this, BusySetSignalName, true);
Window.AlertManager.RequestPageBusy(this, true);
else
_pendingActions.Add(() => MessagingCenter.Send(this, BusySetSignalName, true));
_pendingActions.Add(() => Window.AlertManager.RequestPageBusy(this, true));
}
#pragma warning restore CS0618 // Type or member is obsolete

OnAppearing();
Appearing?.Invoke(this, EventArgs.Empty);
Expand All @@ -677,10 +669,8 @@ public void SendDisappearing()

_hasAppeared = false;

#pragma warning disable CS0618 // TODO: Remove when we internalize/replace MessagingCenter
if (IsBusy)
MessagingCenter.Send(this, BusySetSignalName, false);
#pragma warning restore CS0618 // Type or member is obsolete
Window.AlertManager.RequestPageBusy(this, false);

var pageContainer = this as IPageContainer<Page>;
pageContainer?.CurrentPage?.SendDisappearing();
Expand Down Expand Up @@ -743,9 +733,7 @@ void OnPageBusyChanged()
{
if (!_hasAppeared)
return;
#pragma warning disable CS0618 // TODO: Remove when we internalize/replace MessagingCenter
MessagingCenter.Send(this, BusySetSignalName, IsBusy);
#pragma warning restore CS0618 // Type or member is obsolete
Window.AlertManager.RequestPageBusy(this, IsBusy);
}

void OnToolbarItemsCollectionChanged(object sender, NotifyCollectionChangedEventArgs args)
Expand Down
70 changes: 10 additions & 60 deletions src/Controls/src/Core/Platform/AlertManager/AlertManager.Android.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#nullable disable
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Android.App;
using Android.Content;
Expand All @@ -21,80 +22,29 @@ namespace Microsoft.Maui.Controls.Platform
{
internal partial class AlertManager
{
readonly List<AlertRequestHelper> Subscriptions = new List<AlertRequestHelper>();

internal void Subscribe(Window window)
private partial IAlertManagerSubscription CreateSubscription(IMauiContext mauiContext)
{
IMauiContext mauiContext = window?.MauiContext;
Context context = mauiContext?.Context;
Context context = mauiContext.Context;
Activity activity = context.GetActivity();

if (Subscriptions.Any(s => s.Activity == activity))
{
return;
}

Subscriptions.Add(new AlertRequestHelper(activity, mauiContext));
}

internal void Unsubscribe(Window window)
{
IMauiContext mauiContext = window?.Handler?.MauiContext;
Context context = mauiContext?.Context;
Activity activity = context?.GetActivity();
if (activity == null)
return;

var toRemove = Subscriptions.Where(s => s.Activity == activity).ToList();

foreach (AlertRequestHelper alertRequestHelper in toRemove)
{
alertRequestHelper.Dispose();
Subscriptions.Remove(alertRequestHelper);
}
}

internal void ResetBusyCount(Activity context)
{
Subscriptions.FirstOrDefault(s => s.Activity == context)?.ResetBusyCount();
return new AlertRequestHelper(activity, mauiContext);
}

internal sealed class AlertRequestHelper : IDisposable
internal sealed partial class AlertRequestHelper
{
int _busyCount;

internal AlertRequestHelper(Activity context, IMauiContext mauiContext)
{
Activity = context;
MauiContext = mauiContext;

#pragma warning disable CS0618 // TODO: Remove when we internalize/replace MessagingCenter
MessagingCenter.Subscribe<Page, bool>(Activity, Page.BusySetSignalName, OnPageBusy);
MessagingCenter.Subscribe<Page, AlertArguments>(Activity, Page.AlertSignalName, OnAlertRequested);
MessagingCenter.Subscribe<Page, PromptArguments>(Activity, Page.PromptSignalName, OnPromptRequested);
MessagingCenter.Subscribe<Page, ActionSheetArguments>(Activity, Page.ActionSheetSignalName, OnActionSheetRequested);
#pragma warning restore CS0618 // Type or member is obsolete
}

public Activity Activity { get; }
public IMauiContext MauiContext { get; }

public void Dispose()
{
#pragma warning disable CS0618 // TODO: Remove when we internalize/replace MessagingCenter
MessagingCenter.Unsubscribe<Page, bool>(Activity, Page.BusySetSignalName);
MessagingCenter.Unsubscribe<Page, AlertArguments>(Activity, Page.AlertSignalName);
MessagingCenter.Unsubscribe<Page, PromptArguments>(Activity, Page.PromptSignalName);
MessagingCenter.Unsubscribe<Page, ActionSheetArguments>(Activity, Page.ActionSheetSignalName);
#pragma warning restore CS0618 // Type or member is obsolete
}

public void ResetBusyCount()
{
_busyCount = 0;
}
public IMauiContext MauiContext { get; }

void OnPageBusy(IView sender, bool enabled)
public partial void OnPageBusy(Page sender, bool enabled)
{
// Verify that the page making the request is part of this activity
if (!PageIsInThisContext(sender))
Expand All @@ -107,7 +57,7 @@ void OnPageBusy(IView sender, bool enabled)
UpdateProgressBarVisibility(_busyCount > 0);
}

void OnActionSheetRequested(IView sender, ActionSheetArguments arguments)
public partial void OnActionSheetRequested(Page sender, ActionSheetArguments arguments)
{
// Verify that the page making the request is part of this activity
if (!PageIsInThisContext(sender))
Expand Down Expand Up @@ -166,7 +116,7 @@ void OnActionSheetRequested(IView sender, ActionSheetArguments arguments)
}
}

void OnAlertRequested(IView sender, AlertArguments arguments)
public partial void OnAlertRequested(Page sender, AlertArguments arguments)
{
// Verify that the page making the request is part of this activity
if (!PageIsInThisContext(sender))
Expand Down Expand Up @@ -246,7 +196,7 @@ TextDirection GetTextDirection(IView sender, FlowDirection flowDirection)
return TextDirection.Ltr;
}

void OnPromptRequested(IView sender, PromptArguments arguments)
public partial void OnPromptRequested(Page sender, PromptArguments arguments)
{
// Verify that the page making the request is part of this activity
if (!PageIsInThisContext(sender))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using Microsoft.Maui.Controls.Internals;

namespace Microsoft.Maui.Controls.Platform
{
internal partial class AlertManager
{
private partial IAlertManagerSubscription CreateSubscription(IMauiContext mauiContext)
{
throw new NotImplementedException();
}

internal partial class AlertRequestHelper
{
public partial void OnActionSheetRequested(Page sender, ActionSheetArguments arguments) { }

public partial void OnAlertRequested(Page sender, AlertArguments arguments) { }

public partial void OnPromptRequested(Page sender, PromptArguments arguments) { }

public partial void OnPageBusy(Page sender, bool enabled) { }
}
}
}
60 changes: 12 additions & 48 deletions src/Controls/src/Core/Platform/AlertManager/AlertManager.Tizen.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#nullable disable
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Maui.Controls.Internals;
Expand All @@ -12,36 +13,14 @@ namespace Microsoft.Maui.Controls.Platform
{
internal partial class AlertManager
{
readonly List<AlertRequestHelper> Subscriptions = new List<AlertRequestHelper>();

internal void Subscribe(Window window)
private partial IAlertManagerSubscription CreateSubscription(IMauiContext mauiContext)
{
var nativeWindow = window?.MauiContext.GetPlatformWindow();
var modalStack = window?.MauiContext.GetModalStack();
if (Subscriptions.Any(s => s.Window == nativeWindow))
return;

Subscriptions.Add(new AlertRequestHelper(nativeWindow, modalStack));
var nativeWindow = mauiContext.GetPlatformWindow();
var modalStack = mauiContext.GetModalStack();
return new AlertRequestHelper(nativeWindow, modalStack);
}

internal void Unsubscribe(Window window)
{
IMauiContext mauiContext = window?.Handler?.MauiContext;
var platformWindow = mauiContext?.GetPlatformWindow();
if (platformWindow == null)
return;

var toRemove = Subscriptions.Where(s => s.Window == platformWindow).ToList();

foreach (AlertRequestHelper alertRequestHelper in toRemove)
{
alertRequestHelper.Dispose();
Subscriptions.Remove(alertRequestHelper);
}
}
}

internal sealed class AlertRequestHelper : IDisposable
internal sealed partial class AlertRequestHelper
{
int _busyCount;
Popup _busyPopup;
Expand All @@ -51,29 +30,12 @@ internal sealed class AlertRequestHelper : IDisposable
internal AlertRequestHelper(NWindow window, NavigationStack modalStack)
{
Window = window;

#pragma warning disable CS0618 // TODO: Remove when we internalize/replace MessagingCenter
MessagingCenter.Subscribe<Page, bool>(Window, Page.BusySetSignalName, OnBusySetRequest);
MessagingCenter.Subscribe<Page, AlertArguments>(Window, Page.AlertSignalName, OnAlertRequest);
MessagingCenter.Subscribe<Page, ActionSheetArguments>(Window, Page.ActionSheetSignalName, OnActionSheetRequest);
MessagingCenter.Subscribe<Page, PromptArguments>(Window, Page.PromptSignalName, OnPromptRequested);
#pragma warning restore CS0618 // Type or member is obsolete
_modalStack = modalStack;
}

public NWindow Window { get; }

public void Dispose()
{
#pragma warning disable CS0618 // TODO: Remove when we internalize/replace MessagingCenter
MessagingCenter.Unsubscribe<Page, AlertArguments>(Window, Page.AlertSignalName);
MessagingCenter.Unsubscribe<Page, bool>(Window, Page.BusySetSignalName);
MessagingCenter.Unsubscribe<Page, ActionSheetArguments>(Window, Page.ActionSheetSignalName);
MessagingCenter.Unsubscribe<Page, PromptArguments>(Window, Page.PromptSignalName);
#pragma warning restore CS0618 // Type or member is obsolete
}

void OnBusySetRequest(Page sender, bool enabled)
public partial void OnPageBusy(Page sender, bool enabled)
{
// Verify that the page making the request is child of this platform
if (!PageIsInThisWindow(sender))
Expand All @@ -99,7 +61,7 @@ void OnBusySetRequest(Page sender, bool enabled)
}
}

async void OnAlertRequest(Page sender, AlertArguments arguments)
public async partial void OnAlertRequested(Page sender, AlertArguments arguments)
{
// Verify that the page making the request is child of this platform
if (!PageIsInThisWindow(sender))
Expand Down Expand Up @@ -130,7 +92,7 @@ await _modalStack.PushDummyPopupPage(async () =>
alert?.Dispose();
}

async void OnActionSheetRequest(Page sender, ActionSheetArguments arguments)
public async partial void OnActionSheetRequested(Page sender, ActionSheetArguments arguments)
{
// Verify that the page making the request is child of this platform
if (!PageIsInThisWindow(sender))
Expand All @@ -150,12 +112,13 @@ await _modalStack.PushDummyPopupPage(async () =>
});
}

async void OnPromptRequested(Page sender, PromptArguments args)
public async partial void OnPromptRequested(Page sender, PromptArguments arguments)
{
// Verify that the page making the request is child of this platform
if (!PageIsInThisWindow(sender))
return;

var args = arguments;

await _modalStack.PushDummyPopupPage(async () =>
{
Expand Down Expand Up @@ -203,4 +166,5 @@ protected override bool OnBackButtonPressed()
}
}
}
}
}
Loading