From 1ff31f156bf7ff36eb93ef1dd9d8e1a162e8769d Mon Sep 17 00:00:00 2001 From: Vignesh-SF3580 <102575140+Vignesh-SF3580@users.noreply.github.com> Date: Thu, 10 Apr 2025 16:48:11 +0530 Subject: [PATCH 1/2] Fixed-14092 : App.Current.PageDisappearing is not raised when a page is popped --- .../src/Core/NavigationPage/NavigationPage.cs | 2 +- .../TestCases.HostApp/Issues/Issue14092.cs | 94 +++++++++++++++++++ .../Tests/Issues/Issue14092.cs | 25 +++++ 3 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 src/Controls/tests/TestCases.HostApp/Issues/Issue14092.cs create mode 100644 src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue14092.cs diff --git a/src/Controls/src/Core/NavigationPage/NavigationPage.cs b/src/Controls/src/Core/NavigationPage/NavigationPage.cs index 8bf135510018..b9a5dd8a5281 100644 --- a/src/Controls/src/Core/NavigationPage/NavigationPage.cs +++ b/src/Controls/src/Core/NavigationPage/NavigationPage.cs @@ -783,6 +783,7 @@ protected async override Task OnPopAsync(bool animated) await Owner.SendHandlerUpdateAsync(animated, () => { + Owner.FireDisappearing(currentPage); Owner.RemoveFromInnerChildren(currentPage); Owner.CurrentPage = newCurrentPage; if (currentPage.TitleView != null) @@ -793,7 +794,6 @@ await Owner.SendHandlerUpdateAsync(animated, () => { Owner.SendNavigating(currentPage); - Owner.FireDisappearing(currentPage); Owner.FireAppearing(newCurrentPage); }, () => diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue14092.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue14092.cs new file mode 100644 index 000000000000..ba49f11eaee6 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue14092.cs @@ -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(); + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue14092.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue14092.cs new file mode 100644 index 000000000000..434a49e4e901 --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue14092.cs @@ -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")); + } +} \ No newline at end of file From 8a2223675fa6d79b7d5a792ab86d9b0b733ece11 Mon Sep 17 00:00:00 2001 From: Vignesh-SF3580 <102575140+Vignesh-SF3580@users.noreply.github.com> Date: Wed, 16 Apr 2025 18:09:53 +0530 Subject: [PATCH 2/2] Fix updated for PopToRoot. --- .../src/Core/NavigationPage/NavigationPage.cs | 2 +- .../TestCases.HostApp/Issues/Issue14092.cs | 58 ++++++++++++++++--- .../Tests/Issues/Issue14092.cs | 16 ++++- 3 files changed, 66 insertions(+), 10 deletions(-) diff --git a/src/Controls/src/Core/NavigationPage/NavigationPage.cs b/src/Controls/src/Core/NavigationPage/NavigationPage.cs index b9a5dd8a5281..e117695f4968 100644 --- a/src/Controls/src/Core/NavigationPage/NavigationPage.cs +++ b/src/Controls/src/Core/NavigationPage/NavigationPage.cs @@ -817,6 +817,7 @@ protected override Task OnPopToRootAsync(bool animated) return Owner.SendHandlerUpdateAsync(animated, () => { + Owner.FireDisappearing(previousPage); var lastIndex = NavigationStack.Count - 1; while (lastIndex > 0) { @@ -830,7 +831,6 @@ protected override Task OnPopToRootAsync(bool animated) () => { Owner.SendNavigating(previousPage); - Owner.FireDisappearing(previousPage); Owner.FireAppearing(newPage); }, () => diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue14092.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue14092.cs index ba49f11eaee6..5d3635b5b2e6 100644 --- a/src/Controls/tests/TestCases.HostApp/Issues/Issue14092.cs +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue14092.cs @@ -14,9 +14,14 @@ public Issue14092() : base(new Issue14092FirstPage()) private void Current_PageDisappearing(object sender, Page e) { - if (e is Issue14092SecondPage) + switch (e) { - _firstPage.UpdateStatusLabel("Disappearing triggered when pop"); + case Issue14092SecondPage: + _firstPage.UpdateStatusLabel("Disappearing triggered when pop"); + break; + case Issue14092ThirdPage: + _firstPage.UpdateStatusLabel("Disappearing triggered when PopToRoot"); + break; } } } @@ -36,14 +41,14 @@ public Issue14092FirstPage() VerticalOptions = LayoutOptions.Center }; - var counterBtn = new Button + var button = new Button { - Text = "Click me", + Text = "Go To Page2", AutomationId = "firstPageButton", HorizontalOptions = LayoutOptions.Fill }; - counterBtn.Clicked += OnCounterClicked; + button.Clicked += OnCounterClicked; Content = new VerticalStackLayout { @@ -52,7 +57,7 @@ public Issue14092FirstPage() Children = { _label, - counterBtn + button } }; } @@ -74,11 +79,48 @@ public Issue14092SecondPage() { Title = "Second Page"; - var button = new Button + var popButton = new Button { Text = "Go Back", AutomationId = "secondPageButton", }; + popButton.Clicked += OnButtonClicked; + + var pushButton = new Button + { + Text = "Go To Page3", + AutomationId = "secondPagePushButton", + }; + pushButton.Clicked += OnPushButtonClicked; + + Content = new StackLayout + { + Children = { popButton, pushButton } + }; + } + + private void OnPushButtonClicked(object sender, EventArgs e) + { + Navigation.PushAsync(new Issue14092ThirdPage()); + } + + private void OnButtonClicked(object sender, EventArgs e) + { + Navigation.PopAsync(); + } +} + +public class Issue14092ThirdPage : ContentPage +{ + public Issue14092ThirdPage() + { + Title = "Third Page"; + + var button = new Button + { + Text = "PopToRoot", + AutomationId = "thirdPageButton", + }; button.Clicked += OnButtonClicked; Content = new StackLayout @@ -89,6 +131,6 @@ public Issue14092SecondPage() private void OnButtonClicked(object sender, EventArgs e) { - Navigation.PopAsync(); + Navigation.PopToRootAsync(); } } \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue14092.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue14092.cs index 434a49e4e901..a7dbdd74f2d3 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue14092.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue14092.cs @@ -13,7 +13,7 @@ public Issue14092(TestDevice testDevice) : base(testDevice) [Test] [Category(UITestCategories.Navigation)] - public void PageDisAppearingTriggeredWhenPop() + public void PageDisappearingTriggeredOnPop() { App.WaitForElement("firstPageButton"); App.Tap("firstPageButton"); @@ -22,4 +22,18 @@ public void PageDisAppearingTriggeredWhenPop() var label = App.WaitForElement("StatusLabel"); Assert.That(label.GetText(), Is.EqualTo("Disappearing triggered when pop")); } + + [Test] + [Category(UITestCategories.Navigation)] + public void PageDisappearingTriggeredOnPopToRoot() + { + App.WaitForElement("firstPageButton"); + App.Tap("firstPageButton"); + App.WaitForElement("secondPagePushButton"); + App.Tap("secondPagePushButton"); + App.WaitForElement("thirdPageButton"); + App.Tap("thirdPageButton"); + var label = App.WaitForElement("StatusLabel"); + Assert.That(label.GetText(), Is.EqualTo("Disappearing triggered when PopToRoot")); + } } \ No newline at end of file