Skip to content
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

Disconnect property changes from all pages when TabbedPage set to null #18458

Merged
merged 3 commits into from Nov 30, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,44 @@
using System;
using System.Threading.Tasks;
using Microsoft.Maui;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Graphics;

namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 18457, "Adding/Removing Pages From Removed TabbedPage Causes Crash")]
public class Issue18457 : TestContentPage
{
bool pagePushed = false;
TabbedPage _tabbedPage = new TabbedPage();
protected override void Init()
{
_tabbedPage.Children.Add(new ContentPage() { Title = "tab 1"});
_tabbedPage.Children.Add(new ContentPage() { Title = "tab 2"});
_tabbedPage.Children.Add(new ContentPage() { Title = "tab 3"});
}

protected override async void OnNavigatedTo(NavigatedToEventArgs args)
{
base.OnNavigatedTo(args);

if (!pagePushed)
{
pagePushed = true;
await Navigation.PushAsync(_tabbedPage);
await Navigation.PopAsync();
_tabbedPage.Children.Add(new ContentPage());
_tabbedPage.Children[0].Background = SolidColorBrush.Purple;
_tabbedPage.Children[0].Title = "update title";
_tabbedPage.Children[0].IconImageSource = "dotnet_bot.png";
await Task.Yield();
Content = new VerticalStackLayout(){
Children =
{
new Label() { Text = "This test pushes and pops a TabbedPage, and then modifies the Children on the popped page."},
new Label() { Text = "If the app doesn't crash, this test has passed.", AutomationId = "Success" }
}
};
}
}
}
5 changes: 3 additions & 2 deletions src/Controls/src/Core/Platform/Android/TabbedPageManager.cs
Expand Up @@ -114,8 +114,9 @@ internal void SetElement(TabbedPage tabbedPage)
var activity = _context.GetActivity();
var themeContext = activity;

if (Element != null)
if (Element is not null)
{
Element.InternalChildren.ForEach(page => TeardownPage(page as Page));
PureWeen marked this conversation as resolved.
Show resolved Hide resolved
((IPageController)Element).InternalChildren.CollectionChanged -= OnChildrenCollectionChanged;
Element.Appearing -= OnTabbedPageAppearing;
Element.Disappearing -= OnTabbedPageDisappearing;
Expand All @@ -124,7 +125,7 @@ internal void SetElement(TabbedPage tabbedPage)
}

Element = tabbedPage;
if (Element != null)
if (Element is not null)
{
_viewPager.LayoutChange += OnLayoutChanged;
Element.Appearing += OnTabbedPageAppearing;
Expand Down