Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ void OnPageBusy(IView sender, bool enabled)

void OnActionSheetRequested(IView sender, ActionSheetArguments arguments)
{
// Wait for handler to be ready before showing dialog
if (WaitForHandlerIfNeeded(sender, () => OnActionSheetRequested(sender, arguments)))
{
return;
}

// Verify that the page making the request is part of this activity
if (!PageIsInThisContext(sender))
{
Expand Down Expand Up @@ -168,6 +174,12 @@ void OnActionSheetRequested(IView sender, ActionSheetArguments arguments)

void OnAlertRequested(IView sender, AlertArguments arguments)
{
// Wait for handler to be ready before showing dialog
if (WaitForHandlerIfNeeded(sender, () => OnAlertRequested(sender, arguments)))
{
return;
}

// Verify that the page making the request is part of this activity
if (!PageIsInThisContext(sender))
{
Expand Down Expand Up @@ -248,6 +260,12 @@ TextDirection GetTextDirection(IView sender, FlowDirection flowDirection)

void OnPromptRequested(IView sender, PromptArguments arguments)
{
// Wait for handler to be ready before showing dialog
if (WaitForHandlerIfNeeded(sender, () => OnPromptRequested(sender, arguments)))
{
return;
}

// Verify that the page making the request is part of this activity
if (!PageIsInThisContext(sender))
{
Expand Down Expand Up @@ -290,6 +308,22 @@ void OnPromptRequested(IView sender, PromptArguments arguments)
editText.RequestFocus();
}

bool WaitForHandlerIfNeeded(IView sender, System.Action action)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be a public extension method useful for developers.

{
if (sender.Handler is null && sender is VisualElement ve)
{
void OnHandlerReady(object s, EventArgs e)
{
ve.HandlerChanged -= OnHandlerReady;
action();
}

ve.HandlerChanged += OnHandlerReady;
return true;
}
return false;
}

void UpdateProgressBarVisibility(bool isBusy)
{
int progressLayoutId = 16908999;
Expand Down
52 changes: 52 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue25585.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 25585, "App Unresponsive when prompting the user from a new page", PlatformAffected.Android)]

public class Issue25585 : Shell
{
public Issue25585()
{
this.FlyoutBehavior = FlyoutBehavior.Flyout;

var shellContent = new ShellContent
{
Title = "Second Page",
Route = "MainPage",
Content = new Issue25585ContentPage()
};

Items.Add(new ShellContent
{
Title = "First Page",
Route = "First",
Content = new ContentPage
{
Content = new Label
{
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
Text = "Go to SecondPage",
AutomationId = "GoToSecondPage",
}
}
});
Items.Add(shellContent);
}
}

public class Issue25585ContentPage : ContentPage
{
public Issue25585ContentPage()
{
Content = new StackLayout
{
Children =
{
new Label { Text = "If DisplayAlert is shown, the test passed" },
}
};
DisplayAlert("Hi", "This is from Constructor", "OK", "Cancel");
Copy link

Copilot AI Oct 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test case only validates DisplayAlert from the constructor. Consider adding test coverage for DisplayActionSheet and DisplayPrompt as well, since the fix addresses all three dialog types and they may have different behavior patterns.

Copilot uses AI. Check for mistakes.
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue25585 : _IssuesUITest
{
public Issue25585(TestDevice device) : base(device) { }

public override string Issue => "App Unresponsive when prompting the user from a new page";
[Test]
[Category(UITestCategories.DisplayAlert)]
public void VerifyDisplayAlertIsShown()
{
App.WaitForElement("GoToSecondPage");
App.TapShellFlyoutIcon();
App.Tap("Second Page");
#if MACCATALYST
App.WaitForElement(AppiumQuery.ById($"action-button--{999 - 0}"));
#else
App.WaitForElement("OK");
#endif
}
}
Loading