Skip to content

[iOS] Fixed Flyout icon not updating when root page changes using InsertPageBefore #29924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 63 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue29921.cs
Original file line number Diff line number Diff line change
@@ -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" },
}
};
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -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();
Copy link
Contributor

Choose a reason for hiding this comment

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

Pending snapshot on Mac and Windows.
image
Could you commit the images?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jsuarezruiz I have updated the pending snapshots for Mac and Windows.

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