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
1 change: 1 addition & 0 deletions src/Controls/src/Core/NavigationProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ protected virtual void OnRemovePage(Page page)
{
currentInner.RemovePage(page);
}
page?.DisconnectHandlers();
}

Page Pop()
Expand Down
140 changes: 140 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue29923.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
namespace Maui.Controls.Sample.Issues;

[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 29923, "Removed page handlers not disconnected when using Navigation.RemovePage()", PlatformAffected.All)]
public partial class Issue29923 : Shell
{
public Issue29923()
{
var rootPage = new ContentPage
{
Title = "Handler Disconnection Test",
Content = new VerticalStackLayout
{
Padding = new Thickness(30, 0),
Spacing = 25,
Children =
{
new Button
{
Text = "Test Page Modal",
AutomationId = "NavigateToTestPageModalButton",
Command = new Command(async () =>
{
var navPage = new NavigationPage();
var page1 = new Issue29923TestPage();
var page2 = new Issue29923TestPage2();

await navPage.PushAsync(page1);
await navPage.PushAsync(page2);

await Navigation.PushModalAsync(navPage);
})
},
new Button
{
Text = "Test Page",
AutomationId = "NavigateToTestPageButton",
Command = new Command(async () =>
{
var page1 = new Issue29923TestPage();
var page2 = new Issue29923TestPage2();

await Navigation.PushAsync(page1);
await Navigation.PushAsync(page2);
})
}
}
}
};

Items.Add(new ShellContent
{
Title = "Handler Test",
Content = rootPage
});
}

public class Issue29923TestPage : ContentPage
{
public Issue29923TestPage()
{
Title = "Test Page";

Content = new VerticalStackLayout
{
Padding = new Thickness(20),
Spacing = 10,
};
}
}

public class Issue29923TestPage2 : ContentPage
{
private Label _handlerStatusLabel;

public Issue29923TestPage2()
{
Title = "Test Page 2";

_handlerStatusLabel = new Label
{
Text = "",
AutomationId = "HandlerStatusLabel",
FontAttributes = FontAttributes.Bold
};

Content = new VerticalStackLayout
{
Padding = new Thickness(20),
Spacing = 10,
Children =
{
new Label
{
Text = "Test Page Removal Scenarios",
FontSize = 18,
FontAttributes = FontAttributes.Bold
},
new Button
{
Text = "Remove Test Page 1",
AutomationId = "RemoveTestPage1Button",
Command = new Command(RemoveFirstPage)
},
new Button
{
Text = "Pop Modal",
AutomationId = "PopModalButton",
Command = new Command(() => Navigation.PopModalAsync())
},
new HorizontalStackLayout
{
Children =
{
new Label { Text = "Is Handler still available:", FontAttributes = FontAttributes.Bold },
_handlerStatusLabel
}
}
}
};
}

private void RemoveFirstPage()
{
var navigationStack = Navigation.NavigationStack;
if (navigationStack.Count == 0)
return;

var pageToRemove = navigationStack.FirstOrDefault();
if (pageToRemove == null && navigationStack.Count > 1)
pageToRemove = navigationStack[1];

if (pageToRemove != null)
{
Navigation.RemovePage(pageToRemove);
_handlerStatusLabel.Text = (pageToRemove.Handler != null).ToString();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue29923 : _IssuesUITest
{
public Issue29923(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "Removed page handlers not disconnected when using Navigation.RemovePage()";

[Test]
[Category(UITestCategories.Navigation)]
public void RemovePageShouldDisconnectHandlers()
{
App.WaitForElement("NavigateToTestPageModalButton");
App.Tap("NavigateToTestPageModalButton");
App.WaitForElement("RemoveTestPage1Button");
App.Tap("RemoveTestPage1Button");
Assert.That(App.WaitForElement("HandlerStatusLabel").GetText(), Is.EqualTo("False"));
App.Tap("PopModalButton");

App.WaitForElement("NavigateToTestPageButton");
App.Tap("NavigateToTestPageButton");
App.WaitForElement("RemoveTestPage1Button");
App.Tap("RemoveTestPage1Button");
Assert.That(App.WaitForElement("HandlerStatusLabel").GetText(), Is.EqualTo("False"));
}
}
Loading