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

NavigationBar properties not updating - fix #23076

Merged
merged 4 commits into from
Aug 14, 2024
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
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.
Loading