Skip to content

Commit

Permalink
Merge pull request #17528 from unoplatform/dev/mazi/ios-traits-compat
Browse files Browse the repository at this point in the history
feat: Listen to trait changes on iOS 17+
  • Loading branch information
jeromelaban authored Nov 27, 2024
2 parents f2f4743 + e98f10b commit f880d6d
Showing 1 changed file with 10 additions and 0 deletions.
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))
{
((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+
}
}

0 comments on commit f880d6d

Please sign in to comment.