Skip to content
This repository was archived by the owner on Sep 12, 2024. It is now read-only.

Commit 0fbe99a

Browse files
committed
Environment values for color schemes
1 parent 790cfd5 commit 0fbe99a

File tree

15 files changed

+179
-52
lines changed

15 files changed

+179
-52
lines changed

Snip.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
79C612B62506A020008672BA /* ExternalSnippet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79C612B52506A020008672BA /* ExternalSnippet.swift */; };
6868
79C612B92506B27F008672BA /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79C612B82506B27F008672BA /* SettingsView.swift */; };
6969
79DBD4CA24D1CBE500568364 /* CodeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79DBD4C924D1CBE500568364 /* CodeView.swift */; };
70+
79EC4827252CA90E00E45AC3 /* EnvironmentValues.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79EC4826252CA90E00E45AC3 /* EnvironmentValues.swift */; };
7071
79F07A2324D2F3DC00469324 /* ModeSelectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79F07A2224D2F3DC00469324 /* ModeSelectionView.swift */; };
7172
79F07A2524D2F9C700469324 /* CodeActionsTopBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79F07A2424D2F9C700469324 /* CodeActionsTopBar.swift */; };
7273
79F07A2724D3028C00469324 /* VisualEffectView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79F07A2624D3028C00469324 /* VisualEffectView.swift */; };
@@ -147,6 +148,7 @@
147148
79C612B52506A020008672BA /* ExternalSnippet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExternalSnippet.swift; sourceTree = "<group>"; };
148149
79C612B82506B27F008672BA /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
149150
79DBD4C924D1CBE500568364 /* CodeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodeView.swift; sourceTree = "<group>"; };
151+
79EC4826252CA90E00E45AC3 /* EnvironmentValues.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnvironmentValues.swift; sourceTree = "<group>"; };
150152
79F07A2224D2F3DC00469324 /* ModeSelectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModeSelectionView.swift; sourceTree = "<group>"; };
151153
79F07A2424D2F9C700469324 /* CodeActionsTopBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodeActionsTopBar.swift; sourceTree = "<group>"; };
152154
79F07A2624D3028C00469324 /* VisualEffectView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VisualEffectView.swift; sourceTree = "<group>"; };
@@ -358,6 +360,7 @@
358360
794D27DA24F6A19C006E3B3D /* Data.swift */,
359361
79284D6E250A23E900210E61 /* Bundle.swift */,
360362
795D51EA252B686C00613D0F /* Binding.swift */,
363+
79EC4826252CA90E00E45AC3 /* EnvironmentValues.swift */,
361364
);
362365
path = Extensions;
363366
sourceTree = "<group>";
@@ -546,6 +549,7 @@
546549
7936F89F24DA02DD00F09AE7 /* TextField.swift in Sources */,
547550
79C612B12506278D008672BA /* DeepLinkManager.swift in Sources */,
548551
79C463D024F44233009B2DA3 /* MarkdownHTMLViewer.swift in Sources */,
552+
79EC4827252CA90E00E45AC3 /* EnvironmentValues.swift in Sources */,
549553
795D51EB252B686C00613D0F /* Binding.swift in Sources */,
550554
79284D6D2507DE7F00210E61 /* PagerView.swift in Sources */,
551555
79956A4724E57AC700B823E1 /* Dictionary.swift in Sources */,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"colors" : [
3+
{
4+
"color" : {
5+
"color-space" : "srgb",
6+
"components" : {
7+
"alpha" : "0.800",
8+
"blue" : "0.000",
9+
"green" : "0.000",
10+
"red" : "0.000"
11+
}
12+
},
13+
"idiom" : "universal"
14+
}
15+
],
16+
"info" : {
17+
"author" : "xcode",
18+
"version" : 1
19+
}
20+
}

Snip/Components/CodeViewer/CodeActionsTopBar.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@ import SwiftUI
1111
struct CodeActionsTopBar: View {
1212

1313
@EnvironmentObject var settings: Settings
14+
15+
@Environment(\.themeSecondaryColor) var themeSecondaryColor
16+
@Environment(\.themeTextColor) var themeTextColor
17+
1418
@ObservedObject var syncManager = SyncManager.shared
1519
@ObservedObject var viewModel: CodeActionsViewModel
20+
1621
@State private var showSharingActions = false
1722
@State private var showInfos = false
1823
@State private var moveRightLeft = false
@@ -29,7 +34,7 @@ struct CodeActionsTopBar: View {
2934
})
3035
)
3136
.font(Font.custom("HelveticaNeue", size: 20))
32-
.foregroundColor(.text)
37+
.foregroundColor(themeTextColor)
3338
.frame(maxHeight: .infinity)
3439
.textFieldStyle(PlainTextFieldStyle())
3540

@@ -113,7 +118,7 @@ struct CodeActionsTopBar: View {
113118
}
114119

115120
}
116-
.background((settings.snipAppTheme == .auto ? Color.secondary : Color.secondaryTheme).opacity(0.4))
121+
.background(themeSecondaryColor.opacity(0.4))
117122
.frame(height: 40)
118123
.padding(EdgeInsets(top: 16,
119124
leading: 16,

Snip/Components/CodeViewer/CodeDetailsBottomBar.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,35 @@ struct CodeDetailsBottomBar: View {
1212

1313
@ObservedObject var viewModel: CodeDetailsViewModel
1414

15+
@Environment(\.themeTextColor) var themeTextColor
16+
1517
var body: some View {
1618
HStack {
1719
Text("\(viewModel.code.characterCount()) characters")
1820
.font(Font.custom("CourierNewPSMT", size: 12))
19-
.foregroundColor(.text)
21+
.foregroundColor(themeTextColor)
2022

2123
Text("\(viewModel.code.wordCount()) words")
2224
.font(Font.custom("CourierNewPSMT", size: 12))
23-
.foregroundColor(.text)
25+
.foregroundColor(themeTextColor)
2426

2527
Text("\(viewModel.code.lineCount()) lines")
2628
.font(Font.custom("CourierNewPSMT", size: 12))
27-
.foregroundColor(.text)
29+
.foregroundColor(themeTextColor)
2830

2931
Spacer()
3032

3133
Button(action: { self.viewModel.copyToClipboard() }) {
3234
Image("ic_clipboard")
3335
.resizable()
36+
.renderingMode(.original)
37+
.colorMultiply(themeTextColor)
3438
.frame(width: 15,
3539
height: 15,
3640
alignment: .center)
3741
.scaledToFit()
3842
Text("Copy to clipboard")
39-
.foregroundColor(.text)
43+
.foregroundColor(themeTextColor)
4044
}
4145
.buttonStyle(PlainButtonStyle())
4246
}

Snip/Components/CodeViewer/CodeViewer.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@ import Combine
1212
struct CodeViewer: View {
1313

1414
@ObservedObject var viewModel: CodeViewerViewModel
15+
1516
@EnvironmentObject var appState: AppState
1617
@EnvironmentObject var settings: Settings
1718
@EnvironmentObject var snipItem: SnipItem
1819

20+
@Environment(\.themeTextColor) var themeTextColor
21+
@Environment(\.themePrimaryColor) var themePrimaryColor
22+
1923
@State private var shouldShowPreview = false
2024

2125
var body: some View {
@@ -94,14 +98,14 @@ struct CodeViewer: View {
9498
Spacer()
9599
Text("Snippet Successfully deleted")
96100
.font(Font.custom("HelveticaNeue-Light", size: 20))
97-
.foregroundColor(.text)
101+
.foregroundColor(themeTextColor)
98102
Spacer()
99103
}
100104
HStack {
101105
Spacer()
102106
Text("Tips: Connect Snip to your GitHub account and save your snippet on Gist.")
103107
.font(Font.custom("HelveticaNeue-Light", size: 16))
104-
.foregroundColor(.text)
108+
.foregroundColor(themeTextColor)
105109
Spacer()
106110
}
107111
.padding(.top, 8)
@@ -113,7 +117,7 @@ struct CodeViewer: View {
113117
minHeight: 0,
114118
maxHeight: .infinity,
115119
alignment: .topLeading)
116-
.background(settings.snipAppTheme == .auto ? Color.primary : Color.primaryTheme)
120+
.background(themePrimaryColor)
117121
.listStyle(PlainListStyle())
118122

119123
}

Snip/Components/CodeViewer/ModeSelectionView.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ struct ModeSelectionView: View {
1212

1313
@ObservedObject var viewModel: ModeSelectionViewModel
1414

15+
@Environment(\.themeTextColor) var themeTextColor
16+
1517
@State var newTag: String = ""
1618

1719
private let modesList = CodeMode.list()
@@ -48,7 +50,7 @@ struct ModeSelectionView: View {
4850
}
4951

5052
var addNewTag: some View {
51-
CustomTextField(placeholder: Text("New Tag").foregroundColor(Color.text.opacity(0.7)),
53+
CustomTextField(placeholder: Text("New Tag").foregroundColor(themeTextColor.opacity(0.7)),
5254
text: $newTag,
5355
commit: {
5456
print("Commit")
@@ -62,7 +64,7 @@ struct ModeSelectionView: View {
6264
})
6365
.frame(width: 60)
6466
.padding(4)
65-
.overlay(RoundedRectangle(cornerRadius: 4).stroke(Color.text.opacity(0.7), lineWidth: 1))
67+
.overlay(RoundedRectangle(cornerRadius: 4).stroke(themeTextColor.opacity(0.7), lineWidth: 1))
6668
.textFieldStyle(PlainTextFieldStyle())
6769
}
6870

Snip/Components/External Snippet/ExternalSnippet.swift

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ import SwiftUI
1111
struct ExternalSnippet: View {
1212

1313
@EnvironmentObject var settings: Settings
14+
15+
@Environment(\.themePrimaryColor) var themePrimaryColor
16+
@Environment(\.themeSecondaryColor) var themeSecondaryColor
17+
@Environment(\.themeTextColor) var themeTextColor
18+
@Environment(\.themeShadowColor) var themeShadowColor
19+
1420
@ObservedObject var viewModel: ExternalSnippetViewModel
21+
1522
@Binding var externalSnipItem: ExternalSnipItem
1623

1724
var body: some View {
@@ -25,15 +32,15 @@ struct ExternalSnippet: View {
2532
VStack {
2633
TextField("Snippet name", text: self.$externalSnipItem.name)
2734
.font(Font.custom("HelveticaNeue", size: 20))
28-
.foregroundColor(.text)
35+
.foregroundColor(themeTextColor)
2936
.frame(maxWidth: .infinity)
3037
.textFieldStyle(PlainTextFieldStyle())
3138
}
3239
.padding(EdgeInsets(top: 8,
3340
leading: 4,
3441
bottom: 8,
3542
trailing: 4))
36-
.background((settings.snipAppTheme == .auto ? Color.secondary : Color.secondaryTheme).opacity(0.8))
43+
.background(themeSecondaryColor.opacity(0.8))
3744

3845
Picker(selection: Binding<Int>(
3946
get: {
@@ -77,7 +84,7 @@ struct ExternalSnippet: View {
7784
}
7885
}) {
7986
Text("Cancel")
80-
.foregroundColor(Color.text)
87+
.foregroundColor(themeTextColor)
8188
.padding(4)
8289
}
8390
.buttonStyle(PlainButtonStyle())
@@ -101,7 +108,7 @@ struct ExternalSnippet: View {
101108
height: viewModel.size.height / 1.5,
102109
alignment: .center)
103110
.padding()
104-
.background((settings.snipAppTheme == .auto ? Color.primary : Color.primaryTheme))
111+
.background(themePrimaryColor)
105112
.cornerRadius(4.0)
106113
.offset(x: 0,
107114
y: self.viewModel.isVisible ? ((viewModel.size.height / 2) - ((viewModel.size.height / 1.5) / 1.5)) : 10000)
@@ -110,7 +117,7 @@ struct ExternalSnippet: View {
110117
}
111118

112119
var backgroundView: some View {
113-
self.viewModel.isVisible ? Color.shadow : Color.clear
120+
self.viewModel.isVisible ? themeShadowColor : Color.clear
114121
}
115122
}
116123

Snip/Components/Misc/ImageButton.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import SwiftUI
1010

1111
struct ImageButton<Content: View>: View {
1212

13+
@Environment(\.themeTextColor) var themeTextColor
14+
1315
let imageName: String
1416
let action: () -> ()
1517
let content: () -> Content?
@@ -18,8 +20,8 @@ struct ImageButton<Content: View>: View {
1820
Button(action: action) {
1921
Image(imageName)
2022
.resizable()
21-
.renderingMode(.template)
22-
.colorMultiply(.text)
23+
.renderingMode(.original)
24+
.colorMultiply(themeTextColor)
2325
.scaledToFit()
2426
.frame(width: 20, height: 20, alignment: .center)
2527
}

Snip/Components/Settings/SettingsView.swift

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import SwiftUI
1111
struct SettingsView: View {
1212

1313
@EnvironmentObject var settings: Settings
14+
15+
@Environment(\.themePrimaryColor) var themePrimaryColor
16+
@Environment(\.themeTextColor) var themeTextColor
17+
@Environment(\.themeShadowColor) var themeShadowColor
18+
1419
@ObservedObject var viewModel: SettingsViewModel
1520

1621
@State private var selectedTheme = 0
@@ -30,6 +35,7 @@ struct SettingsView: View {
3035
Spacer()
3136
Text("Settings")
3237
.font(.largeTitle)
38+
.foregroundColor(themeTextColor)
3339
Spacer()
3440
}
3541
.padding(.top, 16)
@@ -45,7 +51,10 @@ struct SettingsView: View {
4551
set: {
4652
selectedAppTheme = $0
4753
settings.snipAppTheme = SnipAppTheme.allCases[$0]
48-
}), label: Text("Application Theme")) {
54+
}), label:
55+
Text("Application Theme")
56+
.foregroundColor(themeTextColor)
57+
) {
4958
ForEach(0 ..< SnipAppTheme.allCases.count) { index in
5059
Text(SnipAppTheme.allCases[index].rawValue).tag(index)
5160
}
@@ -66,7 +75,10 @@ struct SettingsView: View {
6675
set: {
6776
selectedTheme = $0
6877
settings.codeViewTheme = CodeViewTheme.list[$0]
69-
}), label: Text("CodeView Theme")) {
78+
}), label:
79+
Text("CodeView Theme")
80+
.foregroundColor(themeTextColor)
81+
) {
7082
ForEach(0 ..< CodeViewTheme.list.count) {
7183
Text(CodeViewTheme.list[$0].rawValue)
7284
}
@@ -98,7 +110,7 @@ struct SettingsView: View {
98110

99111
HStack {
100112
Text("CodeView Text Size")
101-
.foregroundColor(.text)
113+
.foregroundColor(themeTextColor)
102114
Spacer()
103115
Slider(value: Binding<Float>(
104116
get: {
@@ -127,7 +139,7 @@ struct SettingsView: View {
127139
Spacer()
128140
Button(action: {
129141
withAnimation(.spring(response: 0.4, dampingFraction: 0.8, blendDuration: 0.3)) { () -> () in
130-
settings.isSettingsOpened.toggle()
142+
viewModel.isVisible = false
131143
}
132144
}) {
133145
Text("Close")
@@ -145,7 +157,7 @@ struct SettingsView: View {
145157
.frame(width: viewModel.size.width / 2.5,
146158
height: viewModel.size.height / 1.5,
147159
alignment: .center)
148-
.background((settings.snipAppTheme == .auto ? Color.primary : Color.primaryTheme))
160+
.background(themePrimaryColor)
149161
.cornerRadius(4.0)
150162
.offset(x: 0,
151163
y: viewModel.isVisible ? (( viewModel.size.height / 2) - ((viewModel.size.height / 1.5) / 1.5)) : 10000)
@@ -155,25 +167,25 @@ struct SettingsView: View {
155167
}
156168

157169
var backgroundView: some View {
158-
viewModel.isVisible ? Color.shadow : Color.clear
170+
viewModel.isVisible ? themeShadowColor : Color.clear
159171
}
160172
}
161173

162174
final class SettingsViewModel: ObservableObject {
163175

164-
var isVisible: Bool
176+
@Binding var isVisible: Bool
165177
var size: CGSize
166178

167-
init(isVisible: Bool, readerSize: CGSize) {
168-
self.isVisible = isVisible
179+
init(isVisible: Binding<Bool>, readerSize: CGSize) {
180+
self._isVisible = isVisible
169181
self.size = readerSize
170182
}
171183

172184
}
173185

174186
struct SettingsView_Previews: PreviewProvider {
175187
static var previews: some View {
176-
SettingsView(viewModel: SettingsViewModel(isVisible: true,
188+
SettingsView(viewModel: SettingsViewModel(isVisible: .constant(true),
177189
readerSize: CGSize(width: 400,height: 300)))
178190
}
179191
}

0 commit comments

Comments
 (0)