diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ShouldAppearItemsWhenTappingOnPickerUsingPushModalAsync.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ShouldAppearItemsWhenTappingOnPickerUsingPushModalAsync.png new file mode 100644 index 000000000000..76dae75546ad Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ShouldAppearItemsWhenTappingOnPickerUsingPushModalAsync.png differ diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue6101.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue6101.cs new file mode 100644 index 000000000000..a0853100367f --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue6101.cs @@ -0,0 +1,65 @@ +namespace Maui.Controls.Sample.Issues; + +[Issue(IssueTracker.Github, 6101, "Picker items do not appear when tapping on the picker while using PushModalAsync for navigation", PlatformAffected.macOS)] + +public class Issue6101Shell : Shell +{ + public Issue6101Shell() + { + FlyoutBehavior = FlyoutBehavior.Disabled; + + ShellContent shellContent = new ShellContent + { + ContentTemplate = new DataTemplate(typeof(Issue6101)), + Route = "MainPage" + }; + + Items.Add(shellContent); + } + + public class Issue6101 : ContentPage + { + public Issue6101() + { + Content = new StackLayout + { + Children = + { + new Button + { + Text = "Navigate to page that opens modal", + AutomationId = "Button", + Command = new Command(() => Navigation.PushModalAsync(new Issue6101Page1())) + } + } + }; + } + } + + public class Issue6101Page1 : ContentPage + { + public Issue6101Page1() + { + Content = new VerticalStackLayout() + { + Children = + { + new Picker + { + AutomationId = "Picker", + ItemsSource = new List { "Item 1", "Item 2", "Item 3" } , + SelectedIndex = 0, + } + } + }; + } + } +} + + + + + + + + diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/ShouldAppearItemsWhenTappingOnPickerUsingPushModalAsync.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/ShouldAppearItemsWhenTappingOnPickerUsingPushModalAsync.png new file mode 100644 index 000000000000..59114eac1588 Binary files /dev/null and b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/ShouldAppearItemsWhenTappingOnPickerUsingPushModalAsync.png differ diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue6101.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue6101.cs new file mode 100644 index 000000000000..79c710f86610 --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue6101.cs @@ -0,0 +1,26 @@ +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues +{ + public class Issue6101 : _IssuesUITest + { + public override string Issue => "Picker items do not appear when tapping on the picker while using PushModalAsync for navigation"; + + public Issue6101(TestDevice device) : base(device) + { + } + + [Test] + [Category(UITestCategories.Picker)] + public void ShouldAppearItemsWhenTappingOnPickerUsingPushModalAsync() + { + App.WaitForElement("Button"); + App.Tap("Button"); + App.WaitForElement("Picker"); + App.Click("Picker"); + VerifyScreenshot(); + } + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ShouldAppearItemsWhenTappingOnPickerUsingPushModalAsync.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ShouldAppearItemsWhenTappingOnPickerUsingPushModalAsync.png new file mode 100644 index 000000000000..ff2f48c4284e Binary files /dev/null and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ShouldAppearItemsWhenTappingOnPickerUsingPushModalAsync.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ShouldAppearItemsWhenTappingOnPickerUsingPushModalAsync.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ShouldAppearItemsWhenTappingOnPickerUsingPushModalAsync.png new file mode 100644 index 000000000000..bf12154345ca Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ShouldAppearItemsWhenTappingOnPickerUsingPushModalAsync.png differ diff --git a/src/Core/src/Handlers/Picker/PickerHandler.iOS.cs b/src/Core/src/Handlers/Picker/PickerHandler.iOS.cs index 2ab45391c4d6..b3bc8dce6e36 100644 --- a/src/Core/src/Handlers/Picker/PickerHandler.iOS.cs +++ b/src/Core/src/Handlers/Picker/PickerHandler.iOS.cs @@ -86,11 +86,27 @@ void DisplayAlert(MauiPicker uITextField) uITextField.EditingDidEnd += editingDidEndHandler; var platformWindow = MauiContext?.GetPlatformWindow(); - platformWindow?.BeginInvokeOnMainThread(() => + if (platformWindow is null) { - _ = platformWindow?.RootViewController?.PresentViewControllerAsync(pickerController, true); + return; + } + + var currentViewController = GetCurrentViewController(platformWindow.RootViewController); + platformWindow.BeginInvokeOnMainThread(() => + { + currentViewController?.PresentViewControllerAsync(pickerController, true); }); } + + static UIViewController? GetCurrentViewController(UIViewController? viewController) + { + while (viewController?.PresentedViewController != null) + { + viewController = viewController.PresentedViewController; + } + + return viewController; + } #endif internal bool UpdateImmediately { get; set; }