Skip to content

Commit

Permalink
Title not updated after OnAppearing for TabbedPage - fix (#22899)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubaflo committed Jun 15, 2024
1 parent 3143629 commit f8ee45a
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 28 deletions.
48 changes: 20 additions & 28 deletions src/Controls/src/Core/NavigationPage/NavigationPageToolbar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,26 @@ void OnToolbarItemsChanged(object sender, EventArgs e)

void OnPagePropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (_currentPage != sender)
return;

OnPropertyChanged(sender, e);
if (e.IsOneOf(NavigationPage.HasNavigationBarProperty,
NavigationPage.HasBackButtonProperty,
NavigationPage.TitleIconImageSourceProperty,
NavigationPage.TitleViewProperty,
NavigationPage.IconColorProperty) ||
e.IsOneOf(Page.TitleProperty,
PlatformConfiguration.AndroidSpecific.AppCompat.NavigationPage.BarHeightProperty,
NavigationPage.BarBackgroundColorProperty,
NavigationPage.BarBackgroundProperty,
NavigationPage.BarTextColorProperty) ||
e.IsOneOf(
PlatformConfiguration.WindowsSpecific.Page.ToolbarDynamicOverflowEnabledProperty,
PlatformConfiguration.WindowsSpecific.Page.ToolbarPlacementProperty))
{
ApplyChanges(_currentNavigationPage);
}
else if (_currentPage != sender && sender == _currentNavigationPage && e.Is(NavigationPage.CurrentPageProperty))
{
ApplyChanges(_currentNavigationPage);
}
}

void OnPageAppearing(object sender, EventArgs e)
Expand Down Expand Up @@ -247,30 +263,6 @@ void ApplyChanges(NavigationPage navigationPage)
DynamicOverflowEnabled = PlatformConfiguration.WindowsSpecific.Page.GetToolbarDynamicOverflowEnabled(_currentPage);
}

void OnPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (sender == _currentNavigationPage && e.Is(NavigationPage.CurrentPageProperty))
{
ApplyChanges(_currentNavigationPage);
}
else if (e.IsOneOf(NavigationPage.HasNavigationBarProperty,
NavigationPage.HasBackButtonProperty,
NavigationPage.TitleIconImageSourceProperty,
NavigationPage.TitleViewProperty,
NavigationPage.IconColorProperty) ||
e.IsOneOf(Page.TitleProperty,
PlatformConfiguration.AndroidSpecific.AppCompat.NavigationPage.BarHeightProperty,
NavigationPage.BarBackgroundColorProperty,
NavigationPage.BarBackgroundProperty,
NavigationPage.BarTextColorProperty) ||
e.IsOneOf(
PlatformConfiguration.WindowsSpecific.Page.ToolbarDynamicOverflowEnabledProperty,
PlatformConfiguration.WindowsSpecific.Page.ToolbarPlacementProperty))
{
ApplyChanges(_currentNavigationPage);
}
}

Color GetBarTextColor() => _currentNavigationPage?.BarTextColor;
Color GetIconColor() => (_currentPage != null) ? NavigationPage.GetIconColor(_currentPage) : null;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue22899 : _IssuesUITest
{
public override string Issue => "Title not updated after OnAppearing for TabbedPage in NavigationPage";

public Issue22899(TestDevice device) : base(device) { }

[Test]
public void Issue22899Test()
{
_ = App.WaitForElement("button");
App.Click("button");
_ = App.WaitForElement("label");

// The test passes if the text in the navigation bar has changed
VerifyScreenshot();
}
}
}
17 changes: 17 additions & 0 deletions src/Controls/tests/TestCases/Issues/Issues22899.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue22899">
<ContentPage Title="Title">
<VerticalStackLayout>
<Button
Text="Update title"
AutomationId="button"
Clicked="Button_Clicked"/>
<Label
Text="Button clicked"
IsVisible="False"
x:Name="label"/>
</VerticalStackLayout>
</ContentPage>
</TabbedPage>
27 changes: 27 additions & 0 deletions src/Controls/tests/TestCases/Issues/Issues22899.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Xaml;

namespace Maui.Controls.Sample.Issues
{
[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 22899, "Title not updated after OnAppearing for TabbedPage in NavigationPage", PlatformAffected.All)]
public class Issue22899NavPage : NavigationPage
{
public Issue22899NavPage() : base(new Issue22899()){ }
}

public partial class Issue22899 : TabbedPage
{
public Issue22899()
{
InitializeComponent();
}

void Button_Clicked(object sender, EventArgs e)
{
Title = "Title has changed";
label.IsVisible = true;
}
}
}

0 comments on commit f8ee45a

Please sign in to comment.