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

feat: Listen to trait changes on iOS 17+ #17528

Merged
merged 3 commits into from
Nov 27, 2024
Merged
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
10 changes: 10 additions & 0 deletions src/Uno.UI/Controls/RootViewController.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ private void Initialize()
UIApplication.Notifications
.ObserveWillResignActive((sender, args) =>
VisualTreeHelper.CloseLightDismissPopups(WinUICoreServices.Instance.ContentRootCoordinator.CoreWindowContentRoot.XamlRoot));

#if NET9_0_OR_GREATER
// iOS 17+ only
if (UIDevice.CurrentDevice.CheckSystemVersion(17, 0))
MartinZikmund marked this conversation as resolved.
Show resolved Hide resolved
{
((IUITraitChangeObservable)this).RegisterForTraitChanges((env, traits) => SystemThemeHelper.RefreshSystemTheme());
}
#endif
}

// This will handle when the status bar is showed / hidden by the system on iPhones
Expand Down Expand Up @@ -87,10 +95,12 @@ public override void MotionEnded(UIEventSubtype motion, UIEvent evt)

public override bool ShouldAutorotate() => CanAutorotate && base.ShouldAutorotate();

#pragma warning disable CA1422 // Deprecated in iOS 17+, replaced by RegisterForTraitChanges in Initialize()
public override void TraitCollectionDidChange(UITraitCollection previousTraitCollection)
{
base.TraitCollectionDidChange(previousTraitCollection);
SystemThemeHelper.RefreshSystemTheme();
}
#pragma warning restore CA1422 // Deprecated in iOS 17+
}
}
Loading