diff --git a/src/Controls/src/Core/Compatibility/Handlers/NavigationPage/iOS/NavigationRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/NavigationPage/iOS/NavigationRenderer.cs index 54366c0e1c15..c6e0c46e39e8 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/NavigationPage/iOS/NavigationRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/NavigationPage/iOS/NavigationRenderer.cs @@ -627,7 +627,14 @@ void InsertPageBefore(Page page, Page before) var pageContainer = CreateViewControllerForPage(page); var target = nvh.ViewController.ParentViewController; - ViewControllers = ViewControllers.Insert(ViewControllers.IndexOf(target), pageContainer); + var index = ViewControllers.IndexOf(target); + ViewControllers = ViewControllers.Insert(index, pageContainer); + + // Update the flyout icon when the root page changes + if (index == 0) + { + (target as ParentingViewController)?.UpdateLeftBarButtonItem(); + } } void OnInsertPageBeforeRequested(object sender, NavigationRequestedEventArgs e) @@ -1506,8 +1513,7 @@ internal void UpdateLeftBarButtonItem(Page pageBeingRemoved = null) return; var currentChild = this.Child; - var firstPage = n.NavPageController.Pages.FirstOrDefault(); - + var firstPage = (n.ViewControllers.FirstOrDefault() as ParentingViewController)?.Child; if (n._parentFlyoutPage == null) return; diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/FlyoutIconUpdatedAfterInsertPageBefore.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/FlyoutIconUpdatedAfterInsertPageBefore.png new file mode 100644 index 000000000000..fc801b91b578 Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/FlyoutIconUpdatedAfterInsertPageBefore.png differ diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue29921.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue29921.cs new file mode 100644 index 000000000000..95c10469bde4 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue29921.cs @@ -0,0 +1,63 @@ +namespace Maui.Controls.Sample.Issues; + +[Issue(IssueTracker.Github, 29921, "Flyout icon not replaced after root page change", PlatformAffected.iOS)] +public class Issue29921 : FlyoutPage +{ + public Issue29921() + { + Detail = new NavigationPage(new Issue29921Page1()); + Flyout = new ContentPage + { + Title = "Flyout Page", + IconImageSource = "menu_icon.png", + Content = new Label + { + Text = "This is flyout", + VerticalOptions = LayoutOptions.Center, + HorizontalOptions = LayoutOptions.Center + } + }; + FlyoutLayoutBehavior = FlyoutLayoutBehavior.Popover; + } +} + +public class Issue29921Page1 : ContentPage +{ + public Issue29921Page1() + { + Title = "Page 1"; + var insertBeforeButton = new Button { Text = "Insert Page Before", AutomationId = "InsertPageButton" }; + insertBeforeButton.Clicked += InsertBefore_Clicked; + Content = new StackLayout + { + VerticalOptions = LayoutOptions.Center, + HorizontalOptions = LayoutOptions.Center, + Children = { insertBeforeButton } + }; + } + + private void InsertBefore_Clicked(object sender, EventArgs e) + { + if (Parent is NavigationPage navPage) + { + navPage.Navigation.InsertPageBefore(new Issue29921Page2(), navPage.RootPage); + } + } +} + +public class Issue29921Page2 : ContentPage +{ + public Issue29921Page2() + { + Title = "Page 2"; + Content = new StackLayout + { + VerticalOptions = LayoutOptions.Center, + HorizontalOptions = LayoutOptions.Center, + Children = + { + new Label { Text = "Flyout icon is visible", AutomationId = "Page2Label" }, + } + }; + } +} diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/FlyoutIconUpdatedAfterInsertPageBefore.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/FlyoutIconUpdatedAfterInsertPageBefore.png new file mode 100644 index 000000000000..f78fcba49019 Binary files /dev/null and b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/FlyoutIconUpdatedAfterInsertPageBefore.png differ diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29921.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29921.cs new file mode 100644 index 000000000000..d0bebe9a58a2 --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29921.cs @@ -0,0 +1,22 @@ +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; + +public class Issue29921 : _IssuesUITest +{ + public Issue29921(TestDevice testDevice) : base(testDevice) + { + } + public override string Issue => "Flyout icon not replaced after root page change"; + + [Test] + [Category(UITestCategories.FlyoutPage)] + public void FlyoutIconUpdatedAfterInsertPageBefore() + { + App.WaitForElement("InsertPageButton"); + App.Tap("InsertPageButton"); + VerifyScreenshot(); + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/FlyoutIconUpdatedAfterInsertPageBefore.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/FlyoutIconUpdatedAfterInsertPageBefore.png new file mode 100644 index 000000000000..6209512d91b0 Binary files /dev/null and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/FlyoutIconUpdatedAfterInsertPageBefore.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/FlyoutIconUpdatedAfterInsertPageBefore.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/FlyoutIconUpdatedAfterInsertPageBefore.png new file mode 100644 index 000000000000..112a4f1c0e1a Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/FlyoutIconUpdatedAfterInsertPageBefore.png differ