87 lines
2.2 KiB
Swift
87 lines
2.2 KiB
Swift
//
|
|
// UIDesignStyle.swift
|
|
// SportsTime
|
|
//
|
|
// UI design style variants for the home screen.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
/// Available UI design aesthetics for the home screen
|
|
enum UIDesignStyle: String, CaseIterable, Identifiable, Codable {
|
|
case classic = "Classic"
|
|
case classicAnimated = "Classic Animated"
|
|
|
|
var id: String { rawValue }
|
|
|
|
var description: String {
|
|
switch self {
|
|
case .classic:
|
|
return "The original SportsTime design"
|
|
case .classicAnimated:
|
|
return "Classic with animated sports backgrounds"
|
|
}
|
|
}
|
|
|
|
var iconName: String {
|
|
switch self {
|
|
case .classic: return "star.fill"
|
|
case .classicAnimated: return "sparkles"
|
|
}
|
|
}
|
|
|
|
var accentColor: Color {
|
|
switch self {
|
|
case .classic: return Color(red: 1.0, green: 0.45, blue: 0.2) // Warm Orange
|
|
case .classicAnimated: return Color(red: 1.0, green: 0.45, blue: 0.2) // Warm Orange (same as Classic)
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - Design Style Manager
|
|
|
|
@Observable
|
|
final class DesignStyleManager {
|
|
static let shared = DesignStyleManager()
|
|
|
|
private let userDefaultsKey = "selectedUIDesignStyle"
|
|
|
|
private(set) var currentStyle: UIDesignStyle {
|
|
didSet {
|
|
UserDefaults.standard.set(currentStyle.rawValue, forKey: userDefaultsKey)
|
|
}
|
|
}
|
|
|
|
private init() {
|
|
if let savedValue = UserDefaults.standard.string(forKey: userDefaultsKey),
|
|
let style = UIDesignStyle(rawValue: savedValue) {
|
|
self.currentStyle = style
|
|
} else {
|
|
self.currentStyle = .classic // Default to original design
|
|
}
|
|
}
|
|
|
|
func setStyle(_ style: UIDesignStyle) {
|
|
currentStyle = style
|
|
}
|
|
|
|
/// Convenience property for animation toggle
|
|
var animationsEnabled: Bool {
|
|
get { currentStyle == .classicAnimated }
|
|
set { currentStyle = newValue ? .classicAnimated : .classic }
|
|
}
|
|
}
|
|
|
|
// MARK: - Environment Key
|
|
|
|
private struct DesignStyleKey: EnvironmentKey {
|
|
static let defaultValue: UIDesignStyle = .classic
|
|
}
|
|
|
|
extension EnvironmentValues {
|
|
var designStyle: UIDesignStyle {
|
|
get { self[DesignStyleKey.self] }
|
|
set { self[DesignStyleKey.self] = newValue }
|
|
}
|
|
}
|