Skip to content

Commit

Permalink
Fix ios
Browse files Browse the repository at this point in the history
  • Loading branch information
martijn00 committed Oct 31, 2019
1 parent bf0a23b commit f134f13
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions Chameleon.iOS/CustomRenderers/PageRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,26 @@ protected override void OnElementChanged(VisualElementChangedEventArgs e)
public override void TraitCollectionDidChange(UITraitCollection previousTraitCollection)
{
base.TraitCollectionDidChange(previousTraitCollection);
Console.WriteLine($"TraitCollectionDidChange: {TraitCollection.UserInterfaceStyle} != {previousTraitCollection.UserInterfaceStyle}");

if (this.TraitCollection.UserInterfaceStyle != previousTraitCollection.UserInterfaceStyle)
if (TraitCollection?.UserInterfaceStyle != previousTraitCollection?.UserInterfaceStyle)
{
SetAppTheme();
}
}

private void SetAppTheme()
{
if (this.TraitCollection.UserInterfaceStyle == UIUserInterfaceStyle.Dark)
Mvx.IoCProvider.TryResolve<IThemeService>(out var themeService);
if (themeService != null)
{
Mvx.IoCProvider.Resolve<IThemeService>().UpdateTheme(Core.Models.ThemeMode.Dark);
}
else
{
Mvx.IoCProvider.Resolve<IThemeService>().UpdateTheme(Core.Models.ThemeMode.Light);
if (TraitCollection.UserInterfaceStyle == UIUserInterfaceStyle.Dark)
{
themeService.UpdateTheme(Core.Models.ThemeMode.Dark);
}
else
{
themeService.UpdateTheme(Core.Models.ThemeMode.Light);
}
}
}
}
Expand Down

0 comments on commit f134f13

Please sign in to comment.