Skip to content

[Android, Windows] Fixed App.Current.PageDisappearing not raised when a page is popped #28998

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 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/Controls/src/Core/NavigationPage/NavigationPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,7 @@ protected async override Task<Page> OnPopAsync(bool animated)
await Owner.SendHandlerUpdateAsync(animated,
() =>
{
Owner.FireDisappearing(currentPage);
Owner.RemoveFromInnerChildren(currentPage);
Owner.CurrentPage = newCurrentPage;
if (currentPage.TitleView != null)
Expand All @@ -793,7 +794,6 @@ await Owner.SendHandlerUpdateAsync(animated,
() =>
{
Owner.SendNavigating(currentPage);
Owner.FireDisappearing(currentPage);
Owner.FireAppearing(newCurrentPage);
},
() =>
Expand Down
94 changes: 94 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue14092.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 14092, "Disappeared was not triggered when popping a page", PlatformAffected.Android)]

public class Issue14092 : NavigationPage
{
Issue14092FirstPage _firstPage;

public Issue14092() : base(new Issue14092FirstPage())
{
_firstPage = (Issue14092FirstPage)CurrentPage;
Application.Current.PageDisappearing += Current_PageDisappearing;
}

private void Current_PageDisappearing(object sender, Page e)
{
if (e is Issue14092SecondPage)
{
_firstPage.UpdateStatusLabel("Disappearing triggered when pop");
}
}
}

public class Issue14092FirstPage : ContentPage
{
Label _label;
public Issue14092FirstPage()
{
Title = "Main Page";

_label = new Label
{
Text = "Status: Ready",
AutomationId = "StatusLabel",
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
};

var counterBtn = new Button
{
Text = "Click me",
AutomationId = "firstPageButton",
HorizontalOptions = LayoutOptions.Fill
};

counterBtn.Clicked += OnCounterClicked;

Content = new VerticalStackLayout
{
Padding = new Thickness(30, 0),
Spacing = 25,
Children =
{
_label,
counterBtn
}
};
}

public void UpdateStatusLabel(string text)
{
_label.Text = text;
}

private void OnCounterClicked(object sender, EventArgs e)
{
Navigation.PushAsync(new Issue14092SecondPage());
}
}

public class Issue14092SecondPage : ContentPage
{
public Issue14092SecondPage()
{
Title = "Second Page";

var button = new Button
{
Text = "Go Back",
AutomationId = "secondPageButton",
};
button.Clicked += OnButtonClicked;

Content = new StackLayout
{
Children = { button }
};
}

private void OnButtonClicked(object sender, EventArgs e)
{
Navigation.PopAsync();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue14092 : _IssuesUITest
{
public Issue14092(TestDevice testDevice) : base(testDevice)
{
}
public override string Issue => "Disappeared was not triggered when popping a page";

[Test]
[Category(UITestCategories.Navigation)]
public void PageDisAppearingTriggeredWhenPop()
{
App.WaitForElement("firstPageButton");
App.Tap("firstPageButton");
App.WaitForElement("secondPageButton");
App.Tap("secondPageButton");
var label = App.WaitForElement("StatusLabel");
Assert.That(label.GetText(), Is.EqualTo("Disappearing triggered when pop"));
}
}