Files
Reflect/Shared/Models/Theme.swift
2022-02-20 14:33:58 -06:00

187 lines
4.5 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 bg: AnyView { get }
var preview: AnyView { get }
var labelColor: Color { get }
}
struct IFeelTheme: Themeable {
var labelColor: Color {
return Color(uiColor: UIColor.label)
}
static var title: String {
return "iFeel"
}
var secondaryBGColor: Color {
return Color(uiColor: UIColor.systemBackground)
}
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 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 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 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))
}
)
}
}