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

Fix TabbedPage title displaying incorrectly #17039

Merged
merged 9 commits into from
Apr 29, 2024
15 changes: 12 additions & 3 deletions src/Controls/src/Core/NavigationPage/NavigationPageToolbar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ void UpdateBackButton()

// Once we have better logic inside core to handle backbutton visiblity this
// code should all go away.
// Windows currently doesn't have logic in core to handle back button visibility
// Windows currently doesn't have logic in core to handle back button visibility
// Android just handles it as part of core which means you get cool animations
// that we don't want to interrupt here.
// that we don't want to interrupt here.
// Once it's all built into core we can remove this code and simplify visibility logic
if (_currentPage.IsSet(NavigationPage.HasBackButtonProperty))
{
Expand Down Expand Up @@ -273,7 +273,16 @@ void OnPropertyChanged(object sender, System.ComponentModel.PropertyChangedEvent

Color GetBarTextColor() => _currentNavigationPage?.BarTextColor;
Color GetIconColor() => (_currentPage != null) ? NavigationPage.GetIconColor(_currentPage) : null;
string GetTitle() => GetTitleView() != null ? String.Empty : _currentPage?.Title;

string GetTitle()
{
if (GetTitleView() != null)
{
return string.Empty;
}

return _currentNavigationPage?.CurrentPage?.Title;
}

VisualElement GetTitleView()
{
Expand Down
16 changes: 16 additions & 0 deletions src/Controls/tests/Core.UnitTests/ToolbarTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@ public async Task TitleAndTitleViewAreMutuallyExclusive()
Assert.Equal("Test Title", toolbar.Title);
}

[Fact]
public void ToolbarTitle_UsesTabbedPageTitleWhenSet()
{
var window = new TestWindow();
IToolbarElement toolbarElement = window;
var tabbedPage = new TabbedPage
{
Title = "Test Title",
Children = { new ContentPage { Title = "Child Test Title" } },
};
window.Page = new NavigationPage(tabbedPage);

var toolbar = (Toolbar)toolbarElement.Toolbar;
Assert.Equal(tabbedPage.Title, toolbar.Title);
}

[Fact]
public async Task InsertPageBeforeRootPageShowsBackButton()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#if IOS || MACCATALYST
using FlyoutViewHandler = Microsoft.Maui.Controls.Handlers.Compatibility.PhoneFlyoutPageRenderer;
using NavigationViewHandler = Microsoft.Maui.Controls.Handlers.Compatibility.NavigationRenderer;
using TabbedRenderer = Microsoft.Maui.Controls.Handlers.Compatibility.TabbedRenderer;
#endif

namespace Microsoft.Maui.DeviceTests
Expand All @@ -38,7 +39,11 @@ void SetupBuilder()
handlers.AddHandler(typeof(Controls.NavigationPage), typeof(NavigationViewHandler));
handlers.AddHandler<Page, PageHandler>();
handlers.AddHandler<Controls.Window, WindowHandlerStub>();
handlers.AddHandler(typeof(TabbedPage), typeof(TabbedViewHandler));
#if IOS || MACCATALYST
handlers.AddHandler(typeof(TabbedPage), typeof(TabbedRenderer));
#else
handlers.AddHandler(typeof(TabbedPage), typeof(TabbedViewHandler));
#endif

SetupShellHandlers(handlers);
});
Expand Down
Loading