diff --git a/Trimble.Modus.Components/Helpers/ThemeManager.cs b/Trimble.Modus.Components/Helpers/ThemeManager.cs index 6ad43d93..73643e42 100644 --- a/Trimble.Modus.Components/Helpers/ThemeManager.cs +++ b/Trimble.Modus.Components/Helpers/ThemeManager.cs @@ -7,59 +7,29 @@ public class ThemeManager private static ResourceDictionary DarkThemeResourceDictionary { get; set; } internal static AppTheme CurrentTheme { get; private set; } - public static void Initialize(ResourceDictionary lightTheme = null, ResourceDictionary darkTheme = null, bool useDarkThemeAsLightTheme = false) + public static void Initialize(ResourceDictionary lightTheme = null, ResourceDictionary darkTheme = null) { var defaultLightTheme = new Styles.LightTheme(); var defaultDarkTheme = new Styles.DarkTheme(); + IncludeFromResources(new Styles.Colors()); if (lightTheme != null && lightTheme.Count > 0) { - - LightThemeResourceDictionary = new ResourceDictionary(); - // Add lightTheme and LightThemeResourceDictionary to the MergedDictionaries of the new ResourceDictionary - LightThemeResourceDictionary.MergedDictionaries.Add(defaultLightTheme); - LightThemeResourceDictionary.MergedDictionaries.Add(lightTheme); - - // LightThemeResourceDictionary = lightTheme; - // var notExistsInDictionary = defaultLightTheme.Where(x => !lightTheme.ContainsKey(x.Key)).ToDictionary(x => x.Key, x => x.Value); - // foreach (var item in notExistsInDictionary) - // { - // var keyExists = LightThemeResourceDictionary.ContainsKey(item.Key); - // if (keyExists) - // { - // LightThemeResourceDictionary[item.Key] = item.Value; - // } - // else - // { - // LightThemeResourceDictionary.Add(item.Key, item.Value); - // } - // } + LightThemeResourceDictionary = UpdateDefaulThemeWithCustomTheme(defaultLightTheme, lightTheme); } else { LightThemeResourceDictionary = defaultLightTheme; } - if (useDarkThemeAsLightTheme) + + if (darkTheme != null && darkTheme.Count > 0) { - DarkThemeResourceDictionary = LightThemeResourceDictionary; + DarkThemeResourceDictionary = UpdateDefaulThemeWithCustomTheme(defaultDarkTheme, darkTheme); } else { - if (darkTheme != null && darkTheme.Count > 0) + if (lightTheme != null && lightTheme.Count > 0) { - DarkThemeResourceDictionary = darkTheme; - var notExistsInDictionary = defaultDarkTheme.Where(x => !darkTheme.ContainsKey(x.Key)).ToDictionary(x => x.Key, x => x.Value); - foreach (var item in notExistsInDictionary) - { - var keyExists = DarkThemeResourceDictionary.ContainsKey(item.Key); - if (keyExists) - { - DarkThemeResourceDictionary[item.Key] = item.Value; - } - else - { - DarkThemeResourceDictionary.Add(item.Key, item.Value); - } - } + DarkThemeResourceDictionary = LightThemeResourceDictionary; } else { @@ -72,6 +42,26 @@ public static void Initialize(ResourceDictionary lightTheme = null, ResourceDict Application.Current.RequestedThemeChanged += Current_RequestedThemeChanged; } + + private static ResourceDictionary UpdateDefaulThemeWithCustomTheme(ResourceDictionary defaultTheme, ResourceDictionary customTheme) + { + var theme = customTheme; + var notExistsInDictionary = defaultTheme.Where(x => !customTheme.ContainsKey(x.Key)).ToDictionary(x => x.Key, x => x.Value); + foreach (var item in notExistsInDictionary) + { + var keyExists = theme.ContainsKey(item.Key); + if (keyExists) + { + theme[item.Key] = item.Value; + } + else + { + theme.Add(item.Key, item.Value); + } + } + return theme; + } + private static void Current_RequestedThemeChanged(object sender, AppThemeChangedEventArgs e) { UpdateTheme(e.RequestedTheme); @@ -83,8 +73,6 @@ public static void UpdateTheme(AppTheme theme = AppTheme.Light) RemoveFromResources(LightThemeResourceDictionary); RemoveFromResources(DarkThemeResourceDictionary); - - IncludeFromResources(new Styles.Colors()); if (theme == AppTheme.Dark) { IncludeFromResources(DarkThemeResourceDictionary); diff --git a/Trimble.Modus.Components/Hosting/AppBuilderExtensions.cs b/Trimble.Modus.Components/Hosting/AppBuilderExtensions.cs index 3f06c6cc..de68601d 100644 --- a/Trimble.Modus.Components/Hosting/AppBuilderExtensions.cs +++ b/Trimble.Modus.Components/Hosting/AppBuilderExtensions.cs @@ -21,8 +21,7 @@ public static class AppBuilderExtensions /// initialized for public static MauiAppBuilder UseTrimbleModus(this MauiAppBuilder builder, ResourceDictionary lightTheme = null, - ResourceDictionary darkTheme = null, - bool useDarkThemeAsLightTheme = false) + ResourceDictionary darkTheme = null) { builder .ConfigureLifecycleEvents(lifecycle => @@ -32,7 +31,7 @@ public static class AppBuilderExtensions { d.OnApplicationCreate(del => { - ThemeManager.Initialize(lightTheme, darkTheme,useDarkThemeAsLightTheme); + ThemeManager.Initialize(lightTheme, darkTheme); }); d.OnBackPressed(activity => Droid.Implementation.AndroidPopups.SendBackPressed()); }); @@ -41,7 +40,7 @@ public static class AppBuilderExtensions { ios.FinishedLaunching((app, resources) => { - ThemeManager.Initialize(lightTheme, darkTheme,useDarkThemeAsLightTheme); + ThemeManager.Initialize(lightTheme, darkTheme); return true; }); }); @@ -50,7 +49,7 @@ public static class AppBuilderExtensions { mac.FinishedLaunching((app, resources) => { - ThemeManager.Initialize(lightTheme, darkTheme, useDarkThemeAsLightTheme); + ThemeManager.Initialize(lightTheme, darkTheme); return true; }); }); diff --git a/Trimble.Modus.Components/Styles/LightTheme.xaml b/Trimble.Modus.Components/Styles/LightTheme.xaml index 26bc38f6..f7f28f49 100644 --- a/Trimble.Modus.Components/Styles/LightTheme.xaml +++ b/Trimble.Modus.Components/Styles/LightTheme.xaml @@ -1,6 +1,7 @@  #0063a3 @@ -22,7 +23,8 @@ - + #0E416C #FFFFFF @@ -81,7 +83,7 @@ #0E416C #353a40 #cbcdd6 - + #CBCDD6 @@ -119,17 +121,17 @@ #0063a3 #353A40 #353A40 - + #f1f1f6 #252a2e #dcedf9 #FFF - + #252a2e #FFF - + #217CBB #90939F @@ -264,7 +266,7 @@ #FFF #90939F #90939F - + #464B52 #217CBB diff --git a/Trimble.Modus.Components/Trimble.Modus.Components.csproj b/Trimble.Modus.Components/Trimble.Modus.Components.csproj index d9dad816..0836efae 100644 --- a/Trimble.Modus.Components/Trimble.Modus.Components.csproj +++ b/Trimble.Modus.Components/Trimble.Modus.Components.csproj @@ -31,7 +31,7 @@ True Trimble.Modus.Components Trimbel Modus - 1.0.2-beta + 1.0.22-beta Trimble Inc Trimble Inc Trimble.Modus.Components