From b58b49a1c19e27e791c47df6376feee7691259f0 Mon Sep 17 00:00:00 2001 From: prajeet shrestha Date: Sat, 31 Dec 2022 01:40:23 +0545 Subject: [PATCH 1/2] Color Set added for light and dark mode. --- .../Sources/DesignSystem/ColorSet.swift | 26 +++++++++++ .../DesignSystem/Resources/Colors.swift | 10 +++++ .../Sources/DesignSystem/Theme.swift | 44 ++++++++++++++----- 3 files changed, 69 insertions(+), 11 deletions(-) create mode 100644 Packages/DesignSystem/Sources/DesignSystem/ColorSet.swift diff --git a/Packages/DesignSystem/Sources/DesignSystem/ColorSet.swift b/Packages/DesignSystem/Sources/DesignSystem/ColorSet.swift new file mode 100644 index 00000000..7b18f768 --- /dev/null +++ b/Packages/DesignSystem/Sources/DesignSystem/ColorSet.swift @@ -0,0 +1,26 @@ +import SwiftUI + +public protocol ColorSet { + var tintColor: Color { get set } + var primaryBackgroundColor: Color { get set } + var secondaryBackgroundColor: Color { get set } + var labelColor: Color { get set } +} + +public struct DarkSet: ColorSet { + public var tintColor: Color = Color(red: 187/255, green: 59/255, blue: 226/255) + public var primaryBackgroundColor: Color = Color(red: 16/255, green: 21/255, blue: 35/255) + public var secondaryBackgroundColor: Color = Color(red: 30/255, green: 35/255, blue: 62/255) + public var labelColor: Color = .white + + public init() {} +} + +public struct LightSet: ColorSet { + public var tintColor: Color = Color(red: 187/255, green: 59/255, blue: 226/255) + public var primaryBackgroundColor: Color = .white + public var secondaryBackgroundColor: Color = Color(hex:0xF0F1F2) + public var labelColor: Color = .black + + public init() {} +} diff --git a/Packages/DesignSystem/Sources/DesignSystem/Resources/Colors.swift b/Packages/DesignSystem/Sources/DesignSystem/Resources/Colors.swift index cd39fac3..5732c533 100644 --- a/Packages/DesignSystem/Sources/DesignSystem/Resources/Colors.swift +++ b/Packages/DesignSystem/Sources/DesignSystem/Resources/Colors.swift @@ -40,3 +40,13 @@ extension Color: RawRepresentable { return CIColor(color: .init(self)) } } + +extension Color { + init(hex: Int, opacity: Double = 1.0) { + let red = Double((hex & 0xff0000) >> 16) / 255.0 + let green = Double((hex & 0xff00) >> 8) / 255.0 + let blue = Double((hex & 0xff) >> 0) / 255.0 + self.init(.sRGB, red: red, green: green, blue: blue, opacity: opacity) + } +} + diff --git a/Packages/DesignSystem/Sources/DesignSystem/Theme.swift b/Packages/DesignSystem/Sources/DesignSystem/Theme.swift index a71d843a..46b610eb 100644 --- a/Packages/DesignSystem/Sources/DesignSystem/Theme.swift +++ b/Packages/DesignSystem/Sources/DesignSystem/Theme.swift @@ -1,15 +1,37 @@ import SwiftUI public class Theme: ObservableObject { - enum ThemeKey: String { - case colorScheme, tint, label, primaryBackground, secondaryBackground - } - - @AppStorage(ThemeKey.colorScheme.rawValue) public var colorScheme: String = "dark" - @AppStorage(ThemeKey.tint.rawValue) public var tintColor: Color = .brand - @AppStorage(ThemeKey.primaryBackground.rawValue) public var primaryBackgroundColor: Color = .primaryBackground - @AppStorage(ThemeKey.secondaryBackground.rawValue) public var secondaryBackgroundColor: Color = .secondaryBackground - @AppStorage(ThemeKey.label.rawValue) public var labelColor: Color = .label - - public init() { } + enum ThemeKey: String { + case colorScheme, tint, label, primaryBackground, secondaryBackground + } + + @AppStorage("is_previously_set") var isSet: Bool = false + @AppStorage(ThemeKey.colorScheme.rawValue) public var colorScheme: String = "dark" { + didSet { + if colorScheme == "dark" { + setColor(set: DarkSet()) + } else { + setColor(set: LightSet()) + } + } + } + @AppStorage(ThemeKey.tint.rawValue) public var tintColor: Color = .black + @AppStorage(ThemeKey.primaryBackground.rawValue) public var primaryBackgroundColor: Color = .white + @AppStorage(ThemeKey.secondaryBackground.rawValue) public var secondaryBackgroundColor: Color = .gray + @AppStorage(ThemeKey.label.rawValue) public var labelColor: Color = .black + + public init() { + + if !isSet { + setColor(set: DarkSet()) + isSet.toggle() + } + } + + public func setColor(set: ColorSet) { + self.tintColor = set.tintColor + self.primaryBackgroundColor = set.primaryBackgroundColor + self.secondaryBackgroundColor = set.secondaryBackgroundColor + self.labelColor = set.labelColor + } } From 8eee1788b6519e5defaff9fb9fa58508ad1e7684 Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Sat, 31 Dec 2022 06:48:09 +0100 Subject: [PATCH 2/2] Lint --- .../Sources/DesignSystem/ColorSet.swift | 32 +++++------ .../Sources/DesignSystem/Theme.swift | 57 +++++++++---------- 2 files changed, 44 insertions(+), 45 deletions(-) diff --git a/Packages/DesignSystem/Sources/DesignSystem/ColorSet.swift b/Packages/DesignSystem/Sources/DesignSystem/ColorSet.swift index 7b18f768..8a3813fe 100644 --- a/Packages/DesignSystem/Sources/DesignSystem/ColorSet.swift +++ b/Packages/DesignSystem/Sources/DesignSystem/ColorSet.swift @@ -1,26 +1,26 @@ import SwiftUI public protocol ColorSet { - var tintColor: Color { get set } - var primaryBackgroundColor: Color { get set } - var secondaryBackgroundColor: Color { get set } - var labelColor: Color { get set } + var tintColor: Color { get set } + var primaryBackgroundColor: Color { get set } + var secondaryBackgroundColor: Color { get set } + var labelColor: Color { get set } } public struct DarkSet: ColorSet { - public var tintColor: Color = Color(red: 187/255, green: 59/255, blue: 226/255) - public var primaryBackgroundColor: Color = Color(red: 16/255, green: 21/255, blue: 35/255) - public var secondaryBackgroundColor: Color = Color(red: 30/255, green: 35/255, blue: 62/255) - public var labelColor: Color = .white - - public init() {} + public var tintColor: Color = Color(red: 187/255, green: 59/255, blue: 226/255) + public var primaryBackgroundColor: Color = Color(red: 16/255, green: 21/255, blue: 35/255) + public var secondaryBackgroundColor: Color = Color(red: 30/255, green: 35/255, blue: 62/255) + public var labelColor: Color = .white + + public init() {} } public struct LightSet: ColorSet { - public var tintColor: Color = Color(red: 187/255, green: 59/255, blue: 226/255) - public var primaryBackgroundColor: Color = .white - public var secondaryBackgroundColor: Color = Color(hex:0xF0F1F2) - public var labelColor: Color = .black - - public init() {} + public var tintColor: Color = Color(red: 187/255, green: 59/255, blue: 226/255) + public var primaryBackgroundColor: Color = .white + public var secondaryBackgroundColor: Color = Color(hex:0xF0F1F2) + public var labelColor: Color = .black + + public init() {} } diff --git a/Packages/DesignSystem/Sources/DesignSystem/Theme.swift b/Packages/DesignSystem/Sources/DesignSystem/Theme.swift index 46b610eb..cf8d2947 100644 --- a/Packages/DesignSystem/Sources/DesignSystem/Theme.swift +++ b/Packages/DesignSystem/Sources/DesignSystem/Theme.swift @@ -1,37 +1,36 @@ import SwiftUI public class Theme: ObservableObject { - enum ThemeKey: String { - case colorScheme, tint, label, primaryBackground, secondaryBackground - } + enum ThemeKey: String { + case colorScheme, tint, label, primaryBackground, secondaryBackground + } - @AppStorage("is_previously_set") var isSet: Bool = false - @AppStorage(ThemeKey.colorScheme.rawValue) public var colorScheme: String = "dark" { - didSet { - if colorScheme == "dark" { - setColor(set: DarkSet()) - } else { - setColor(set: LightSet()) - } - } + @AppStorage("is_previously_set") var isSet: Bool = false + @AppStorage(ThemeKey.colorScheme.rawValue) public var colorScheme: String = "dark" { + didSet { + if colorScheme == "dark" { + setColor(set: DarkSet()) + } else { + setColor(set: LightSet()) + } } - @AppStorage(ThemeKey.tint.rawValue) public var tintColor: Color = .black - @AppStorage(ThemeKey.primaryBackground.rawValue) public var primaryBackgroundColor: Color = .white - @AppStorage(ThemeKey.secondaryBackground.rawValue) public var secondaryBackgroundColor: Color = .gray - @AppStorage(ThemeKey.label.rawValue) public var labelColor: Color = .black + } + @AppStorage(ThemeKey.tint.rawValue) public var tintColor: Color = .black + @AppStorage(ThemeKey.primaryBackground.rawValue) public var primaryBackgroundColor: Color = .white + @AppStorage(ThemeKey.secondaryBackground.rawValue) public var secondaryBackgroundColor: Color = .gray + @AppStorage(ThemeKey.label.rawValue) public var labelColor: Color = .black - public init() { - - if !isSet { - setColor(set: DarkSet()) - isSet.toggle() - } - } - - public func setColor(set: ColorSet) { - self.tintColor = set.tintColor - self.primaryBackgroundColor = set.primaryBackgroundColor - self.secondaryBackgroundColor = set.secondaryBackgroundColor - self.labelColor = set.labelColor + public init() { + if !isSet { + setColor(set: DarkSet()) + isSet.toggle() } + } + + public func setColor(set: ColorSet) { + self.tintColor = set.tintColor + self.primaryBackgroundColor = set.primaryBackgroundColor + self.secondaryBackgroundColor = set.secondaryBackgroundColor + self.labelColor = set.labelColor + } }