Skip to content

Commit

Permalink
NavigationBar properties not updating - fix (#23076)
Browse files Browse the repository at this point in the history
* Title not updated after OnAppearing for TabbedPage - fix (#22899)

* Added a test category

* Update Issues22899.xaml

* Added snapshots
  • Loading branch information
kubaflo authored Aug 14, 2024
1 parent 6c21d39 commit fa9e370
Show file tree
Hide file tree
Showing 7 changed files with 90 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issues22899.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?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"
AutomationId="label"
IsVisible="False"
x:Name="label"/>
</VerticalStackLayout>
</ContentPage>
</TabbedPage>
27 changes: 27 additions & 0 deletions src/Controls/tests/TestCases.HostApp/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;
}
}
}
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 Issue22899 : _IssuesUITest
{
public override string Issue => "Title not updated after OnAppearing for TabbedPage in NavigationPage";

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

[Test]
[Category(UITestCategories.TabbedPage)]
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();
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fa9e370

Please sign in to comment.