Skip to content

Commit

Permalink
Fix display of ActionSheet in modal view on Windows (dotnet#21295)
Browse files Browse the repository at this point in the history
* Fix display of ActionSheet in modal view on Windows

* Add ui test to validate DisplayActionSheet behaviro in modal dialog

* Give ActionSheet title an AutomationId to improve testing

* Replace baseline with image from ci/cd

* Undo change to app.xaml

* Update AlertManager.Windows.cs
  • Loading branch information
japarson authored Mar 27, 2024
1 parent 8ca7648 commit 794f224
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 2 deletions.
44 changes: 44 additions & 0 deletions src/Controls/samples/Controls.Sample.UITests/Issues/Issue14829.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Microsoft.Maui.Controls;
using Microsoft.Maui.Graphics;

namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.Github, 14829, "DisplayActionSheet still not working on Windows", PlatformAffected.UWP)]
public class Issue14829 : TestContentPage
{
protected override void Init()
{
var navPage = new NavigationPage(new MainPage());
NavigatedTo += Issue14829_NavigatedTo;

async void Issue14829_NavigatedTo(object sender, NavigatedToEventArgs e)
{
NavigatedTo -= Issue14829_NavigatedTo;

await Navigation.PushModalAsync(navPage);
}
}

public partial class MainPage : ContentPage
{
protected override void OnAppearing()
{
Content = new VerticalStackLayout()
{
new Button()
{
AutomationId = "DisplayActionSheetButton",
Command = new Command(async () =>
{
await DisplayActionSheet("ActionSheet: Send to?", "Cancel", null, "Email", "Twitter", "Facebook");
}),
Text = "Click to Display Action Sheet"
}
};
Content.BackgroundColor = Colors.White;

base.OnAppearing();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public ActionSheetContent(ActionSheetArguments sheetOptions)
_options = sheetOptions;

TitleBlock.Text = _options.Title ?? string.Empty;
TitleBlock.SetAutomationPropertiesAutomationId("ActionSheetTitle");

OptionsList.ItemsSource = _options.Buttons.ToList();

if (_options.FlowDirection == Maui.FlowDirection.RightToLeft)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ void OnActionSheetRequested(Page sender, ActionSheetArguments arguments)

try
{
var current = sender.ToPlatform(VirtualView.RequireMauiContext());
var current = sender.ToPlatform();
var pageParent = current?.Parent as FrameworkElement;

if (pageParent != null)
Expand Down Expand Up @@ -252,4 +252,4 @@ bool PageIsInThisWindow(Page page) =>
page?.Window == VirtualView;
}
}
}
}
27 changes: 27 additions & 0 deletions src/Controls/tests/UITests/Tests/Issues/Issue14829.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.AppiumTests.Issues
{
public class Issue14829 : _IssuesUITest
{
public Issue14829(TestDevice device) : base(device)
{
}

public override string Issue => "DisplayActionSheet still not working on Windows";

[Test]
[Category(UITestCategories.ActionSheet)]
public void Issue14829Test()
{
this.IgnoreIfPlatforms(new TestDevice[] { TestDevice.Android, TestDevice.Mac, TestDevice.iOS }, "Only affects Windows.");

App.WaitForElement("DisplayActionSheetButton", timeout: TimeSpan.FromSeconds(4)).Click();
App.WaitForElement("ActionSheetTitle", timeout: TimeSpan.FromSeconds(4));

VerifyScreenshot();
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 794f224

Please sign in to comment.