built out themes a bit more

This commit is contained in:
Trey t
2022-02-06 14:15:16 -06:00
parent ea8ce75058
commit 3c6adce544
6 changed files with 108 additions and 80 deletions

View File

@@ -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))
}
)
}
}

View File

@@ -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)

View File

@@ -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)
)
}

View File

@@ -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)
}

View File

@@ -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))

View File

@@ -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])