Skip to content
Merged
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
9 changes: 6 additions & 3 deletions src/Controls/src/Core/NavigationPage/NavigationPage.Legacy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ async Task<Page> RemoveAsyncInner(

FireDisappearing(page);

if (InternalChildren.Last() == page)
FireAppearing((Page)InternalChildren[NavigationPageController.StackDepth - 2]);

var args = new NavigationRequestedEventArgs(page, animated);

var removed = true;
Expand All @@ -62,8 +59,14 @@ async Task<Page> RemoveAsyncInner(
if (!removed && !fast)
return CurrentPage;

bool isLastPage = InternalChildren.Last() == page;
RemoveFromInnerChildren(page);

if (isLastPage && NavigationPageController.StackDepth >= 2)
{
FireAppearing((Page)InternalChildren[NavigationPageController.StackDepth - 2]);
}

CurrentPage = (Page)InternalChildren.Last();

if (Popped != null)
Expand Down
111 changes: 111 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue28414.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 28414, "NavigationStack updated when OnAppearing triggered", PlatformAffected.iOS)]

public class Issue28414 : NavigationPage
{
public Issue28414() : base(new Issue28414FirstPage())
{

}
}

public class Issue28414FirstPage : ContentPage
{
public Issue28414FirstPage()
{
Title = "FirstPage";

var navigateButton = new Button
{
Text = "Go to second page",
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center,
AutomationId = "FirstPageButton"
};

navigateButton.Clicked += async (sender, args) =>
{
await Navigation.PushAsync(new Issue28414SecondPage());
};

Content = new VerticalStackLayout
{
Children = { navigateButton }
};
}
}

public class Issue28414SecondPage : ContentPage
{
private Label label;

public Issue28414SecondPage()
{
Title = "SecondPage";

label = new Label
{
Text = "Initial state",
AutomationId = "OnAppearingLabel"
};

var navigateButton = new Button
{
Text = "Go to third page",
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center,
AutomationId = "SecondPageButton"
};

navigateButton.Clicked += async (sender, args) =>
{
label.Text = string.Empty;
await Navigation.PushAsync(new Issue28414ThirdPage());
};

Content = new VerticalStackLayout
{
Children = { label, navigateButton }
};
}

protected override void OnAppearing()
{
base.OnAppearing();
if (Navigation.NavigationStack.Count == 2)
{
label.Text = $"Stack has {Navigation.NavigationStack.Count} pages";
}
else
{
label.Text = "Page not popped yet";
}
}
}

public class Issue28414ThirdPage : ContentPage
{
public Issue28414ThirdPage()
{
Title = "ThirdPage";

var button = new Button
{
Text = "Go Back",
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
AutomationId = "ThirdPageButton"
};

button.Clicked += async (sender, args) =>
{
await Navigation.PopAsync();
};

Content = new VerticalStackLayout
{
Children = { button }
};
}
}
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.TestCases.Tests.Issues;

public class Issue28414 : _IssuesUITest
{
public Issue28414(TestDevice testDevice) : base(testDevice)
{
}
public override string Issue => "NavigationStack updated when OnAppearing triggered";

[Test]
[Category(UITestCategories.Navigation)]
public void NavigationStackUpdatesOnPop()
{
App.WaitForElement("FirstPageButton");
App.Tap("FirstPageButton");
App.WaitForElement("SecondPageButton");
App.Tap("SecondPageButton");
App.WaitForElement("ThirdPageButton");
App.Tap("ThirdPageButton");
var label = App.WaitForElement("OnAppearingLabel");
Assert.That(label.GetText(), Is.EqualTo("Stack has 2 pages"));
}
}