From 53bdd92e72402b4f7fe60d1283e52f53961d0874 Mon Sep 17 00:00:00 2001 From: kspearrin Date: Mon, 30 Sep 2019 21:39:50 -0400 Subject: [PATCH] support dark theme default on extensions --- .../CredentialProviderViewController.cs | 2 +- src/iOS.Core/Utilities/ThemeHelpers.cs | 13 ++++++++++--- src/iOS.Core/Utilities/iOSCoreHelpers.cs | 4 ++-- src/iOS.Extension/LoadingViewController.cs | 2 +- src/iOS/AppDelegate.cs | 2 +- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/iOS.Autofill/CredentialProviderViewController.cs b/src/iOS.Autofill/CredentialProviderViewController.cs index 9ed85cd6b..67ad2a47a 100644 --- a/src/iOS.Autofill/CredentialProviderViewController.cs +++ b/src/iOS.Autofill/CredentialProviderViewController.cs @@ -276,7 +276,7 @@ namespace Bit.iOS.Autofill _initedHockeyApp = true; } iOSCoreHelpers.Bootstrap(); - iOSCoreHelpers.AppearanceAdjustments(); + iOSCoreHelpers.AppearanceAdjustments(deviceActionService); } private void InitAppIfNeeded() diff --git a/src/iOS.Core/Utilities/ThemeHelpers.cs b/src/iOS.Core/Utilities/ThemeHelpers.cs index 6e5957f13..3c5f113a2 100644 --- a/src/iOS.Core/Utilities/ThemeHelpers.cs +++ b/src/iOS.Core/Utilities/ThemeHelpers.cs @@ -6,6 +6,7 @@ namespace Bit.iOS.Core.Utilities public static class ThemeHelpers { public static bool LightTheme = true; + public static bool UsingOsDarkTheme = false; public static UIColor SplashBackgroundColor = Xamarin.Forms.Color.FromHex("#efeff4").ToUIColor(); public static UIColor BackgroundColor = Xamarin.Forms.Color.FromHex("#ffffff").ToUIColor(); public static UIColor MutedColor = Xamarin.Forms.Color.FromHex("#777777").ToUIColor(); @@ -18,8 +19,9 @@ namespace Bit.iOS.Core.Utilities public static UIColor NavBarBackgroundColor = Xamarin.Forms.Color.FromHex("#3c8dbc").ToUIColor(); public static UIColor NavBarTextColor = Xamarin.Forms.Color.FromHex("#ffffff").ToUIColor(); - public static void SetAppearance(string theme) + public static void SetAppearance(string theme, bool usingOsDarkTheme) { + UsingOsDarkTheme = usingOsDarkTheme; SetThemeVariables(theme); UINavigationBar.Appearance.ShadowImage = new UIImage(); UINavigationBar.Appearance.SetBackgroundImage(new UIImage(), UIBarMetrics.Default); @@ -30,9 +32,9 @@ namespace Bit.iOS.Core.Utilities } } - public static void SetExtensionAppearance(string theme) + public static void SetExtensionAppearance(string theme, bool usingOsDarkTheme) { - SetAppearance(theme); + SetAppearance(theme, usingOsDarkTheme); UIView.Appearance.BackgroundColor = BackgroundColor; UILabel.Appearance.TextColor = TextColor; UITextField.Appearance.TintColor = TextColor; @@ -57,6 +59,11 @@ namespace Bit.iOS.Core.Utilities private static void SetThemeVariables(string theme) { LightTheme = false; + if(string.IsNullOrWhiteSpace(theme) && UsingOsDarkTheme) + { + theme = "dark"; + } + if(theme == "dark") { var whiteColor = Xamarin.Forms.Color.FromHex("#ffffff").ToUIColor(); diff --git a/src/iOS.Core/Utilities/iOSCoreHelpers.cs b/src/iOS.Core/Utilities/iOSCoreHelpers.cs index 224bb1758..db2320634 100644 --- a/src/iOS.Core/Utilities/iOSCoreHelpers.cs +++ b/src/iOS.Core/Utilities/iOSCoreHelpers.cs @@ -72,9 +72,9 @@ namespace Bit.iOS.Core.Utilities var bootstrapTask = BootstrapAsync(); } - public static void AppearanceAdjustments() + public static void AppearanceAdjustments(IDeviceActionService deviceActionService) { - ThemeHelpers.SetAppearance(ThemeManager.GetTheme(false)); + ThemeHelpers.SetAppearance(ThemeManager.GetTheme(false), deviceActionService.UsingDarkTheme()); UIApplication.SharedApplication.StatusBarHidden = false; UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.LightContent; } diff --git a/src/iOS.Extension/LoadingViewController.cs b/src/iOS.Extension/LoadingViewController.cs index f68639d4b..2af8566f7 100644 --- a/src/iOS.Extension/LoadingViewController.cs +++ b/src/iOS.Extension/LoadingViewController.cs @@ -395,7 +395,7 @@ namespace Bit.iOS.Extension _initedHockeyApp = true; } iOSCoreHelpers.Bootstrap(); - iOSCoreHelpers.AppearanceAdjustments(); + iOSCoreHelpers.AppearanceAdjustments(deviceActionService); } private bool IsLocked() diff --git a/src/iOS/AppDelegate.cs b/src/iOS/AppDelegate.cs index 78a48fe48..9c69b6bd8 100644 --- a/src/iOS/AppDelegate.cs +++ b/src/iOS/AppDelegate.cs @@ -59,7 +59,7 @@ namespace Bit.iOS _eventService = ServiceContainer.Resolve("eventService"); LoadApplication(new App.App(null)); - iOSCoreHelpers.AppearanceAdjustments(); + iOSCoreHelpers.AppearanceAdjustments(_deviceActionService); ZXing.Net.Mobile.Forms.iOS.Platform.Init(); _broadcasterService.Subscribe(nameof(AppDelegate), async (message) =>