Skip to content

Commit

Permalink
feat: Listen to trat changes on iOS 17+
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Nov 23, 2024
1 parent feff443 commit d851ac9
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 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,12 @@ private void Initialize()
UIApplication.Notifications
.ObserveWillResignActive((sender, args) =>
VisualTreeHelper.CloseLightDismissPopups(WinUICoreServices.Instance.ContentRootCoordinator.CoreWindowContentRoot.XamlRoot));

// iOS 17+ only
if (UIDevice.CurrentDevice.CheckSystemVersion(17, 0))
{
((IUITraitChangeObservable)this).RegisterForTraitChanges<UITraitUserInterfaceStyle>((env, traits) => SystemThemeHelper.RefreshSystemTheme());
}
}

// This will handle when the status bar is showed / hidden by the system on iPhones
Expand Down Expand Up @@ -87,10 +93,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 d851ac9

Please sign in to comment.