From 3c6adce54437772bc291ba8ea3f9664ffdbd8003 Mon Sep 17 00:00:00 2001 From: Trey t Date: Sun, 6 Feb 2022 14:15:16 -0600 Subject: [PATCH] built out themes a bit more --- Shared/Models/Theme.swift | 134 ++++++++++++++++----------- Shared/views/AddMoodHeaderView.swift | 4 +- Shared/views/ContentView.swift | 10 +- Shared/views/FilterView.swift | 14 +-- Shared/views/SettingsView.swift | 24 ++--- Shared/views/SwitchableView.swift | 2 +- 6 files changed, 108 insertions(+), 80 deletions(-) diff --git a/Shared/Models/Theme.swift b/Shared/Models/Theme.swift index 6dd8c15..71203b4 100644 --- a/Shared/Models/Theme.swift +++ b/Shared/Models/Theme.swift @@ -1,5 +1,5 @@ // -// Theme.swift +// theme.currentTheme.swift // Feels (iOS) // // Created by Trey Tartt on 2/4/22. @@ -7,65 +7,93 @@ import SwiftUI -enum Theme: Int, CaseIterable { +struct ThemeConstants { static let iconSize: CGFloat = 50 +} + +enum Theme: Int, CaseIterable { case system - case ifeelTheme + case iFeel var title: String { switch self { + case .system: + return SystemTheme.title + case .iFeel: + return IFeelTheme.title + } + } + + var currentTheme: Themeable { + switch self { case .system: - return "System" - case .ifeelTheme: - return "iFeel Theme" - } - } - - var secondaryBGColor: UIColor { - switch self{ - case .system: - return UIColor.secondarySystemBackground - case .ifeelTheme: - return UIColor.systemBackground - } - } - - var bg: some View { - switch self { - case .system: - return AnyView( - ZStack { - Rectangle() - .fill(Color(UIColor.systemBackground)) - } - ) - case .ifeelTheme: - return AnyView( - BGView().equatable() - ) - } - } - - var preview: some View { - switch self { - case .system: - return AnyView( - ZStack { - Rectangle() - .fill(Color(UIColor.secondarySystemBackground)) - .frame(width: Theme.iconSize, height: Theme.iconSize) - .clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous)) - } - ) - case .ifeelTheme: - return AnyView( - ZStack { - BGView().equatable() - .frame(width: Theme.iconSize, height: Theme.iconSize) - .clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous)) - } - ) + return SystemTheme() + case .iFeel: + return IFeelTheme() } } } + +protocol Themeable { + static var title: String { get } + var secondaryBGColor: UIColor { get } + var bg: AnyView { get } + var preview: AnyView { get } +} + +struct IFeelTheme: Themeable { + static var title: String { + return "iFeel Theme" + } + + var secondaryBGColor: UIColor { + return 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 { + static var title: String { + return "System" + } + + var secondaryBGColor: UIColor { + return 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)) + } + ) + } +} diff --git a/Shared/views/AddMoodHeaderView.swift b/Shared/views/AddMoodHeaderView.swift index ed8c664..4886dd6 100644 --- a/Shared/views/AddMoodHeaderView.swift +++ b/Shared/views/AddMoodHeaderView.swift @@ -20,7 +20,7 @@ struct AddMoodHeaderView: View { var body: some View { ZStack { - Color(theme.secondaryBGColor) + Color(theme.currentTheme.secondaryBGColor) VStack { Text(self.getTitle()) @@ -47,7 +47,7 @@ struct AddMoodHeaderView: View { .padding([.leading, .trailing, .bottom]) } .background( - Color(theme.secondaryBGColor) + Color(theme.currentTheme.secondaryBGColor) ) .cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) .frame(minHeight: 88, maxHeight: 150) diff --git a/Shared/views/ContentView.swift b/Shared/views/ContentView.swift index 724487f..ac2884b 100644 --- a/Shared/views/ContentView.swift +++ b/Shared/views/ContentView.swift @@ -203,7 +203,7 @@ struct ContentView: View { ) } .background( - Color(theme.secondaryBGColor) + Color(theme.currentTheme.secondaryBGColor) ) .coordinateSpace(name: "scroll") .onPreferenceChange(ViewOffsetKey.self) { value in @@ -223,7 +223,7 @@ struct ContentView: View { .frame(maxWidth: .infinity, alignment: .leading) .padding() .background( - Color(theme.secondaryBGColor) + Color(theme.currentTheme.secondaryBGColor) ) } @@ -305,7 +305,7 @@ struct ContentView: View { private var emptyView: some View { ZStack { - Color(theme.secondaryBGColor) + Color(theme.currentTheme.secondaryBGColor) VStack { Text(String(localized: "content_view_empty_title")) @@ -347,7 +347,7 @@ struct ContentView: View { VStack { SmallRollUpHeaderView(fakeData: false, backDays: 30) .background( - Color(theme.secondaryBGColor) + Color(theme.currentTheme.secondaryBGColor) ) .cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) .padding() @@ -365,7 +365,7 @@ struct ContentView: View { } .padding(.bottom, 5) .background( - theme.bg + theme.currentTheme.bg .edgesIgnoringSafeArea(.all) ) } diff --git a/Shared/views/FilterView.swift b/Shared/views/FilterView.swift index 94e6bd2..b648531 100644 --- a/Shared/views/FilterView.swift +++ b/Shared/views/FilterView.swift @@ -66,7 +66,7 @@ struct FilterView: View { } .padding(.bottom, 5) .background( - theme.bg + theme.currentTheme.bg .edgesIgnoringSafeArea(.all) ) } @@ -81,7 +81,7 @@ struct FilterView: View { .frame(maxWidth: .infinity) .frame(height: 44) .foregroundColor(Color(UIColor.label)) - .background(Color(theme.secondaryBGColor)) + .background(Color(theme.currentTheme.secondaryBGColor)) .cornerRadius(10) }).frame(maxWidth: .infinity) } @@ -103,7 +103,7 @@ struct FilterView: View { private var statsView: some View { ZStack { - Color(theme.secondaryBGColor) + Color(theme.currentTheme.secondaryBGColor) HStack { Spacer() @@ -120,7 +120,7 @@ struct FilterView: View { VStack { VStack { ZStack { - Color(theme.secondaryBGColor) + Color(theme.currentTheme.secondaryBGColor) DatePicker( String(localized: "filter_view_begin_date"), selection: $viewModel.entryStartDate, @@ -135,7 +135,7 @@ struct FilterView: View { .padding([.leading, .trailing]) ZStack { - Color(theme.secondaryBGColor) + Color(theme.currentTheme.secondaryBGColor) DatePicker( String(localized: "filter_view_end_date"), selection: $viewModel.entryEndDate, @@ -150,7 +150,7 @@ struct FilterView: View { .padding([.leading, .trailing]) ZStack { - Color(theme.secondaryBGColor) + Color(theme.currentTheme.secondaryBGColor) HStack { Spacer() ForEach(weekdays.indices, id: \.self) { dayIdx in @@ -204,7 +204,7 @@ struct FilterView: View { .font(.title) yearGridView(yearData: yearData, columns: columns) .background( - Color(theme.secondaryBGColor) + Color(theme.currentTheme.secondaryBGColor) ) .cornerRadius(10) } diff --git a/Shared/views/SettingsView.swift b/Shared/views/SettingsView.swift index 2d64a0b..dc05022 100644 --- a/Shared/views/SettingsView.swift +++ b/Shared/views/SettingsView.swift @@ -59,7 +59,7 @@ struct SettingsView: View { }) } .background( - theme.bg + theme.currentTheme.bg .edgesIgnoringSafeArea(.all) ) } @@ -79,7 +79,7 @@ struct SettingsView: View { private var specialThanksCell: some View { ZStack { - Color(theme.secondaryBGColor) + Color(theme.currentTheme.secondaryBGColor) VStack { Button(action: { withAnimation{ @@ -102,7 +102,7 @@ struct SettingsView: View { private var addTestDataCell: some View { ZStack { - Color(theme.secondaryBGColor) + Color(theme.currentTheme.secondaryBGColor) Button(action: { PersistenceController.shared.populateTestData() editedDataClosure() @@ -117,7 +117,7 @@ struct SettingsView: View { private var clearDB: some View { ZStack { - Color(theme.secondaryBGColor) + Color(theme.currentTheme.secondaryBGColor) Button(action: { PersistenceController.shared.clearDB() editedDataClosure() @@ -132,7 +132,7 @@ struct SettingsView: View { private var whyBackgroundMode: some View { ZStack { - Color(theme.secondaryBGColor) + Color(theme.currentTheme.secondaryBGColor) VStack { Button(action: { withAnimation{ @@ -159,7 +159,7 @@ struct SettingsView: View { private var changeIcon: some View { ZStack { - Color(theme.secondaryBGColor) + Color(theme.currentTheme.secondaryBGColor) VStack { Text(String(localized: "settings_view_change_icon")) HStack { @@ -196,7 +196,7 @@ struct SettingsView: View { private var showOnboardingButton: some View { ZStack { - Color(theme.secondaryBGColor) + Color(theme.currentTheme.secondaryBGColor) Button(action: { showOnboarding.toggle() }, label: { @@ -210,7 +210,7 @@ struct SettingsView: View { private var cloudKitEnable: some View { ZStack { - Color(theme.secondaryBGColor) + Color(theme.currentTheme.secondaryBGColor) VStack { Toggle(String(localized: "settings_use_cloudkit_title"), isOn: $useCloudKit) @@ -228,7 +228,7 @@ struct SettingsView: View { private var cloudKitStatus: some View { ZStack { - Color(theme.secondaryBGColor) + Color(theme.currentTheme.secondaryBGColor) VStack { Image(systemName: syncMonitor.syncStateSummary.symbolName) .foregroundColor(syncMonitor.syncStateSummary.symbolColor) @@ -242,7 +242,7 @@ struct SettingsView: View { private var canDelete: some View { ZStack { - Color(theme.secondaryBGColor) + Color(theme.currentTheme.secondaryBGColor) VStack { Toggle(String(localized: "settings_use_delete_enable"), isOn: $deleteEnabled) @@ -255,7 +255,7 @@ struct SettingsView: View { private var themePicker: some View { ZStack { - Color(theme.secondaryBGColor) + Color(theme.currentTheme.secondaryBGColor) VStack { Text(String(localized: "settings_background_title")) HStack { @@ -265,7 +265,7 @@ struct SettingsView: View { theme = aTheme }, label: { VStack { - aTheme.preview + aTheme.currentTheme.preview .overlay( Circle() .stroke(Color(UIColor.systemGray), style: StrokeStyle(lineWidth: 2)) diff --git a/Shared/views/SwitchableView.swift b/Shared/views/SwitchableView.swift index 288239b..3c91969 100644 --- a/Shared/views/SwitchableView.swift +++ b/Shared/views/SwitchableView.swift @@ -52,7 +52,7 @@ struct SwitchableView: View { .padding(.top, -12) } .background( - Color(theme.secondaryBGColor) + Color(theme.currentTheme.secondaryBGColor) ) .contentShape(Rectangle()) .cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])