Skip to content

[Mac Catalyst] TitleBar not reacting on UserAppTheme changes #30525

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kubaflo
Copy link
Contributor

@kubaflo kubaflo commented Jul 10, 2025

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Description of Change

This needs to be fixed on Windows, likewise

Issues Fixed

Fixes #30518

Before After
Screen.Recording.2025-07-10.at.02.20.20.mov
Screen.Recording.2025-07-10.at.02.21.04.mov

@Copilot Copilot AI review requested due to automatic review settings July 10, 2025 00:23
@kubaflo kubaflo requested a review from a team as a code owner July 10, 2025 00:23
@kubaflo kubaflo self-assigned this Jul 10, 2025
@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Jul 10, 2025
Copy link
Contributor

Hey there @@kubaflo! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR ensures the custom TitleBar updates its background color when the user switches app themes by reacting to trait collection changes.

  • Added an override of TraitCollectionDidChange to reset the TitleBar’s background on theme change.
  • Used UIColor.SecondarySystemBackground for adaptive coloring.
  • Suppressed CA1422 warnings around the base call for backward‐compatibility checks.
Comments suppressed due to low confidence (1)

src/Core/src/Platform/iOS/WindowViewController.cs:74

  • This override handles theme changes at runtime; please add a corresponding UI test in TestCases.HostApp and an automated test in TestCases.Shared.Tests to verify that the TitleBar background updates correctly when the app theme changes.
	public override void TraitCollectionDidChange(UITraitCollection? previousTraitCollection)

Comment on lines +76 to +79
#pragma warning disable CA1422 // Validate platform compatibility
base.TraitCollectionDidChange(previousTraitCollection);
#pragma warning restore CA1422 // Validate platform compatibility

Copy link
Preview

Copilot AI Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than disabling the platform compatibility analyzer via pragmas, consider using platform compatibility guards such as if (OperatingSystem.IsIOSVersionAtLeast(13)) or marking the override with [SupportedOSPlatform("ios13.0")] to clearly express the iOS 13+ dependency and maintain analyzer support.

Suggested change
#pragma warning disable CA1422 // Validate platform compatibility
base.TraitCollectionDidChange(previousTraitCollection);
#pragma warning restore CA1422 // Validate platform compatibility
[SupportedOSPlatform("ios13.0")]
public override void TraitCollectionDidChange(UITraitCollection? previousTraitCollection)
{
base.TraitCollectionDidChange(previousTraitCollection);
if (_titleBar is not null && _iTitleBarRef.TryGetTarget(out IView? iTitleBar) && iTitleBar?.Background is null)
{
_titleBar.BackgroundColor = UIColor.SecondarySystemBackground;
}
}

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-titlebar community ✨ Community Contribution platform/macos macOS / Mac Catalyst
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Mac Catalyst][Windows] TitleBar not reacting on UserAppTheme changes
1 participant