204 lines
5.0 KiB
Swift
204 lines
5.0 KiB
Swift
//
|
|
// theme.currentTheme.swift
|
|
// Feels (iOS)
|
|
//
|
|
// Created by Trey Tartt on 2/4/22.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct ThemeConstants {
|
|
static let iconSize: CGFloat = 50
|
|
}
|
|
|
|
enum Theme: Int, CaseIterable {
|
|
case system
|
|
case iFeel
|
|
case dark
|
|
case light
|
|
|
|
var title: String {
|
|
switch self {
|
|
case .system:
|
|
return SystemTheme.title
|
|
case .iFeel:
|
|
return IFeelTheme.title
|
|
case .dark:
|
|
return AlwaysDark.title
|
|
case .light:
|
|
return AlwaysLight.title
|
|
}
|
|
}
|
|
|
|
var currentTheme: Themeable {
|
|
switch self {
|
|
|
|
case .system:
|
|
return SystemTheme()
|
|
case .iFeel:
|
|
return IFeelTheme()
|
|
case .dark:
|
|
return AlwaysDark()
|
|
case .light:
|
|
return AlwaysLight()
|
|
}
|
|
}
|
|
}
|
|
|
|
protocol Themeable {
|
|
static var title: String { get }
|
|
var secondaryBGColor: Color { get }
|
|
var bgColor: Color { get }
|
|
var bg: AnyView { get }
|
|
var preview: AnyView { get }
|
|
var labelColor: Color { get }
|
|
}
|
|
|
|
struct IFeelTheme: Themeable {
|
|
var bgColor: Color {
|
|
return Color(uiColor: UIColor.systemBackground)
|
|
}
|
|
|
|
var labelColor: Color {
|
|
return Color(uiColor: UIColor.label)
|
|
}
|
|
|
|
static var title: String {
|
|
return "iFeel"
|
|
}
|
|
|
|
var secondaryBGColor: Color {
|
|
return Color(uiColor: UIColor.secondarySystemBackground)
|
|
}
|
|
|
|
var bg: AnyView {
|
|
return AnyView(
|
|
BGView().equatable()
|
|
)
|
|
}
|
|
|
|
var preview: AnyView {
|
|
return AnyView(
|
|
ZStack {
|
|
BGView().equatable()
|
|
.frame(width: ThemeConstants.iconSize, height: ThemeConstants.iconSize)
|
|
.clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous))
|
|
}
|
|
)
|
|
}
|
|
}
|
|
|
|
struct SystemTheme: Themeable {
|
|
var bgColor: Color {
|
|
return Color(uiColor: UIColor.systemBackground)
|
|
}
|
|
|
|
var labelColor: Color {
|
|
return Color(uiColor: UIColor.label)
|
|
}
|
|
|
|
static var title: String {
|
|
return "System"
|
|
}
|
|
|
|
var secondaryBGColor: Color {
|
|
return Color(uiColor: UIColor.secondarySystemBackground)
|
|
}
|
|
|
|
var bg: AnyView {
|
|
return AnyView(
|
|
ZStack {
|
|
Rectangle()
|
|
.fill(Color(UIColor.systemBackground))
|
|
}
|
|
)
|
|
}
|
|
|
|
var preview: AnyView {
|
|
return AnyView(
|
|
ZStack {
|
|
Rectangle()
|
|
.fill(Color(UIColor.secondarySystemBackground))
|
|
.frame(width: ThemeConstants.iconSize, height: ThemeConstants.iconSize)
|
|
.clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous))
|
|
}
|
|
)
|
|
}
|
|
}
|
|
|
|
struct AlwaysDark: Themeable {
|
|
var bgColor: Color {
|
|
return Color(uiColor: UIColor.systemBackground.resolvedColor(with: .init(userInterfaceStyle: .dark)))
|
|
}
|
|
|
|
var labelColor: Color {
|
|
return .white
|
|
}
|
|
|
|
static var title: String {
|
|
return "Dark"
|
|
}
|
|
|
|
var secondaryBGColor: Color {
|
|
return Color(uiColor: UIColor.secondarySystemBackground.resolvedColor(with: .init(userInterfaceStyle: .dark)))
|
|
}
|
|
|
|
var bg: AnyView {
|
|
return AnyView(
|
|
ZStack {
|
|
Rectangle()
|
|
.fill(Color(UIColor.systemBackground.resolvedColor(with: .init(userInterfaceStyle: .dark))))
|
|
}
|
|
)
|
|
}
|
|
|
|
var preview: AnyView {
|
|
return AnyView(
|
|
ZStack {
|
|
Rectangle()
|
|
.fill(Color(UIColor.secondarySystemBackground.resolvedColor(with: .init(userInterfaceStyle: .dark))))
|
|
.frame(width: ThemeConstants.iconSize, height: ThemeConstants.iconSize)
|
|
.clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous))
|
|
}
|
|
)
|
|
}
|
|
}
|
|
|
|
struct AlwaysLight: Themeable {
|
|
var bgColor: Color {
|
|
return Color(uiColor: UIColor.systemBackground)
|
|
}
|
|
|
|
var labelColor: Color {
|
|
return .black
|
|
}
|
|
|
|
static var title: String {
|
|
return "Light"
|
|
}
|
|
|
|
var secondaryBGColor: Color {
|
|
return Color(uiColor: UIColor.secondarySystemBackground.resolvedColor(with: .init(userInterfaceStyle: .light)))
|
|
}
|
|
|
|
var bg: AnyView {
|
|
return AnyView(
|
|
ZStack {
|
|
Rectangle()
|
|
.fill(Color(UIColor.systemBackground.resolvedColor(with: .init(userInterfaceStyle: .light))))
|
|
}
|
|
)
|
|
}
|
|
|
|
var preview: AnyView {
|
|
return AnyView(
|
|
ZStack {
|
|
Rectangle()
|
|
.fill(Color(UIColor.secondarySystemBackground.resolvedColor(with: .init(userInterfaceStyle: .light))))
|
|
.frame(width: ThemeConstants.iconSize, height: ThemeConstants.iconSize)
|
|
.clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous))
|
|
}
|
|
)
|
|
}
|
|
}
|