Skip to content

Commit

Permalink
Changes for modus color customation
Browse files Browse the repository at this point in the history
  • Loading branch information
Sofiya-kumar committed May 9, 2024
1 parent 266e12f commit d1c4f7a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 53 deletions.
68 changes: 28 additions & 40 deletions Trimble.Modus.Components/Helpers/ThemeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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);
Expand All @@ -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);
Expand Down
9 changes: 4 additions & 5 deletions Trimble.Modus.Components/Hosting/AppBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public static class AppBuilderExtensions
/// <returns><see cref="MauiAppBuilder"/> initialized for <see cref="CommunityToolkit.Maui"/></returns>
public static MauiAppBuilder UseTrimbleModus(this MauiAppBuilder builder,
ResourceDictionary lightTheme = null,
ResourceDictionary darkTheme = null,
bool useDarkThemeAsLightTheme = false)
ResourceDictionary darkTheme = null)
{
builder
.ConfigureLifecycleEvents(lifecycle =>
Expand All @@ -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());
});
Expand All @@ -41,7 +40,7 @@ public static class AppBuilderExtensions
{
ios.FinishedLaunching((app, resources) =>
{
ThemeManager.Initialize(lightTheme, darkTheme,useDarkThemeAsLightTheme);
ThemeManager.Initialize(lightTheme, darkTheme);
return true;
});
});
Expand All @@ -50,7 +49,7 @@ public static class AppBuilderExtensions
{
mac.FinishedLaunching((app, resources) =>
{
ThemeManager.Initialize(lightTheme, darkTheme, useDarkThemeAsLightTheme);
ThemeManager.Initialize(lightTheme, darkTheme);
return true;
});
});
Expand Down
16 changes: 9 additions & 7 deletions Trimble.Modus.Components/Styles/LightTheme.xaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<ResourceDictionary xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:styles="clr-namespace:Trimble.Modus.Components.Styles"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:styles="clr-namespace:Trimble.Modus.Components.Styles"
x:Class="Trimble.Modus.Components.Styles.LightTheme">

<Color x:Key="PrimaryColor">#0063a3</Color>
Expand All @@ -22,7 +23,8 @@

<!--Button-->
<!--Fill Button-->
<styles:ReferenceColor x:Key="PrimaryFillButtonBackgroundColor" Color="{StaticResource PrimaryColor}"/>
<styles:ReferenceColor x:Key="PrimaryFillButtonBackgroundColor"
Color="{StaticResource PrimaryColor}" />
<!--<Color x:Key="PrimaryFillButtonBackgroundColor">#0063a3</Color>-->
<Color x:Key="PrimaryFillButtonSelectedBackgroundColor">#0E416C</Color>
<Color x:Key="PrimaryFillButtonTextColor">#FFFFFF</Color>
Expand Down Expand Up @@ -81,7 +83,7 @@
<Color x:Key="CardSelectedStrokeColor">#0E416C</Color>
<Color x:Key="CardShadowColor">#353a40</Color>
<Color x:Key="CardHoverBackgroundColor">#cbcdd6</Color>

<!--Chip-->
<!--FillChip-->
<Color x:Key="DefaultChipBackgroundColor">#CBCDD6</Color>
Expand Down Expand Up @@ -119,17 +121,17 @@
<Color x:Key="SegmentItemPrimaryBackgroundColor">#0063a3</Color>
<Color x:Key="SegmentItemSecondaryBackgroundColor">#353A40</Color>
<Color x:Key="SegmentedControlBorderColor">#353A40</Color>

<!--Datagrid-->
<Color x:Key="DataGridHeaderColor">#f1f1f6</Color>
<Color x:Key="DataGridHeaderTextColor">#252a2e</Color>
<Color x:Key="DataGridActiveRowColor">#dcedf9</Color>
<Color x:Key="DataGridDefaultRowColor">#FFF</Color>

<!--Modal-->
<Color x:Key="ModalTextAndImageColor">#252a2e</Color>
<Color x:Key="ModalBackgroundColor">#FFF</Color>

<!--Switch-->
<Color x:Key="SwitchOnBackgroundColor">#217CBB</Color>
<Color x:Key="SwitchOffBackgroundColor">#90939F</Color>
Expand Down Expand Up @@ -264,7 +266,7 @@
<Color x:Key="SearchBarSecondaryColor">#FFF</Color>
<Color x:Key="SearchBarIconPrimaryColor">#90939F</Color>
<Color x:Key="SearchBarIconSecondaryColor">#90939F</Color>

<!--Input-->
<Color x:Key="InputDefaultBorderColor">#464B52</Color>
<Color x:Key="InputPrimaryBorderColor">#217CBB</Color>
Expand Down
2 changes: 1 addition & 1 deletion Trimble.Modus.Components/Trimble.Modus.Components.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageId>Trimble.Modus.Components</PackageId>
<Title>Trimbel Modus</Title>
<Version>1.0.2-beta</Version>
<Version>1.0.22-beta</Version>
<Authors>Trimble Inc</Authors>
<Company>Trimble Inc</Company>
<Product>Trimble.Modus.Components</Product>
Expand Down

0 comments on commit d1c4f7a

Please sign in to comment.