Color Set added for light and dark mode.
This commit is contained in:
commit
423df5f4b4
|
@ -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() {}
|
||||||
|
}
|
|
@ -40,3 +40,13 @@ extension Color: RawRepresentable {
|
||||||
return CIColor(color: .init(self))
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,14 +2,35 @@ import SwiftUI
|
||||||
|
|
||||||
public class Theme: ObservableObject {
|
public class Theme: ObservableObject {
|
||||||
enum ThemeKey: String {
|
enum ThemeKey: String {
|
||||||
case colorScheme, tint, label, primaryBackground, secondaryBackground
|
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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@AppStorage(ThemeKey.colorScheme.rawValue) public var colorScheme: String = "dark"
|
public func setColor(set: ColorSet) {
|
||||||
@AppStorage(ThemeKey.tint.rawValue) public var tintColor: Color = .brand
|
self.tintColor = set.tintColor
|
||||||
@AppStorage(ThemeKey.primaryBackground.rawValue) public var primaryBackgroundColor: Color = .primaryBackground
|
self.primaryBackgroundColor = set.primaryBackgroundColor
|
||||||
@AppStorage(ThemeKey.secondaryBackground.rawValue) public var secondaryBackgroundColor: Color = .secondaryBackground
|
self.secondaryBackgroundColor = set.secondaryBackgroundColor
|
||||||
@AppStorage(ThemeKey.label.rawValue) public var labelColor: Color = .label
|
self.labelColor = set.labelColor
|
||||||
|
}
|
||||||
public init() { }
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue