Skip to content

Commit 2c83d50

Browse files
fix: naming of themes
1 parent 1051aca commit 2c83d50

File tree

1 file changed

+283
-0
lines changed

1 file changed

+283
-0
lines changed
Lines changed: 283 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,283 @@
1+
//
2+
// ThemeGalleryView.swift
3+
// GitDiffExample
4+
//
5+
// Created by Tornike Gomareli on 18.06.25.
6+
//
7+
8+
import SwiftUI
9+
import gitdiff
10+
11+
struct ThemeGalleryView: View {
12+
@State private var selectedTheme: DiffTheme = .light
13+
@State private var showingFullScreen = false
14+
@State private var showingCustomThemeCreator = false
15+
16+
let themes: [(name: String, theme: DiffTheme, icon: String, description: String)] = [
17+
("Light", .light, "sun.max.fill", "Clean GitHub-style theme with excellent readability"),
18+
("Dark", .dark, "moon.fill", "Modern dark theme for comfortable night coding"),
19+
("GitLab", .gitlab, "square.and.arrow.up", "GitLab's clean and professional diff style")
20+
]
21+
22+
let columns = [
23+
GridItem(.flexible()),
24+
GridItem(.flexible())
25+
]
26+
27+
var body: some View {
28+
NavigationView {
29+
ScrollView {
30+
VStack(spacing: 20) {
31+
LazyVGrid(columns: columns, spacing: 16) {
32+
ForEach(themes, id: \.name) { theme in
33+
ThemeCard(
34+
name: theme.name,
35+
theme: theme.theme,
36+
icon: theme.icon,
37+
description: theme.description,
38+
isSelected: selectedTheme == theme.theme
39+
) {
40+
withAnimation(.spring()) {
41+
selectedTheme = theme.theme
42+
}
43+
}
44+
}
45+
}
46+
.padding()
47+
48+
// Custom Theme Button
49+
Button(action: { showingCustomThemeCreator = true }) {
50+
HStack {
51+
Image(systemName: "paintbrush.pointed.fill")
52+
Text("Create Custom Theme")
53+
}
54+
.font(.headline)
55+
.foregroundColor(.white)
56+
.frame(maxWidth: .infinity)
57+
.padding()
58+
.background(
59+
LinearGradient(
60+
colors: [.purple, .blue],
61+
startPoint: .leading,
62+
endPoint: .trailing
63+
)
64+
)
65+
.cornerRadius(12)
66+
}
67+
.padding(.horizontal)
68+
69+
VStack(alignment: .leading, spacing: 12) {
70+
HStack {
71+
Text("Preview")
72+
.font(.title2.bold())
73+
74+
Spacer()
75+
76+
Button(action: { showingFullScreen = true }) {
77+
Label("Full Screen", systemImage: "arrow.up.left.and.arrow.down.right")
78+
.font(.caption)
79+
}
80+
}
81+
82+
DiffRenderer(diffText: sampleDiff)
83+
.diffTheme(selectedTheme)
84+
.background(Color.white)
85+
.cornerRadius(12)
86+
.shadow(color: .black.opacity(0.1), radius: 5)
87+
}
88+
.padding()
89+
}
90+
}
91+
.background(Color(.systemGroupedBackground))
92+
.navigationTitle("Theme Gallery")
93+
.sheet(isPresented: $showingFullScreen) {
94+
FullScreenPreview(theme: selectedTheme)
95+
}
96+
.sheet(isPresented: $showingCustomThemeCreator) {
97+
CustomThemeCreator(selectedTheme: $selectedTheme)
98+
}
99+
}
100+
}
101+
102+
private let sampleDiff = """
103+
diff --git a/Theme.swift b/Theme.swift
104+
index 1234567..abcdefg 100644
105+
--- a/Theme.swift
106+
+++ b/Theme.swift
107+
@@ -5,10 +5,12 @@ import Foundation
108+
109+
struct Theme {
110+
let name: String
111+
- let primaryColor: UIColor
112+
- let secondaryColor: UIColor
113+
+ let primaryColor: Color
114+
+ let secondaryColor: Color
115+
+ let accentColor: Color
116+
117+
init(name: String) {
118+
self.name = name
119+
+ // Initialize with default colors
120+
}
121+
}
122+
"""
123+
}
124+
125+
struct ThemeCard: View {
126+
let name: String
127+
let theme: DiffTheme
128+
let icon: String
129+
let description: String
130+
let isSelected: Bool
131+
let action: () -> Void
132+
133+
var body: some View {
134+
Button(action: action) {
135+
VStack(alignment: .leading, spacing: 12) {
136+
HStack {
137+
Image(systemName: icon)
138+
.font(.title2)
139+
.foregroundColor(isSelected ? .white : .blue)
140+
141+
Spacer()
142+
143+
if isSelected {
144+
Image(systemName: "checkmark.circle.fill")
145+
.foregroundColor(.white)
146+
}
147+
}
148+
149+
Text(name)
150+
.font(.headline)
151+
.foregroundColor(isSelected ? .white : .primary)
152+
153+
Text(description)
154+
.font(.caption)
155+
.foregroundColor(isSelected ? .white.opacity(0.8) : .secondary)
156+
.lineLimit(2)
157+
158+
HStack(spacing: 8) {
159+
RoundedRectangle(cornerRadius: 4)
160+
.fill(theme.addedBackground)
161+
.frame(height: 20)
162+
RoundedRectangle(cornerRadius: 4)
163+
.fill(theme.removedBackground)
164+
.frame(height: 20)
165+
}
166+
}
167+
.padding()
168+
.background(
169+
isSelected ?
170+
LinearGradient(
171+
colors: [.blue, .blue.opacity(0.8)],
172+
startPoint: .topLeading,
173+
endPoint: .bottomTrailing
174+
) :
175+
LinearGradient(
176+
colors: [Color(.systemBackground)],
177+
startPoint: .topLeading,
178+
endPoint: .bottomTrailing
179+
)
180+
)
181+
.cornerRadius(12)
182+
.overlay(
183+
RoundedRectangle(cornerRadius: 12)
184+
.stroke(isSelected ? Color.clear : Color.gray.opacity(0.2), lineWidth: 1)
185+
)
186+
.shadow(color: isSelected ? .blue.opacity(0.3) : .black.opacity(0.05), radius: 5)
187+
}
188+
.buttonStyle(PlainButtonStyle())
189+
}
190+
}
191+
192+
struct FullScreenPreview: View {
193+
let theme: DiffTheme
194+
@Environment(\.dismiss) var dismiss
195+
196+
var body: some View {
197+
NavigationView {
198+
DiffRenderer(diffText: SampleDiffs.largeDiff)
199+
.diffTheme(theme)
200+
.navigationTitle("Full Screen Preview")
201+
.navigationBarTitleDisplayMode(.inline)
202+
.toolbar {
203+
ToolbarItem(placement: .navigationBarTrailing) {
204+
Button("Done") {
205+
dismiss()
206+
}
207+
}
208+
}
209+
}
210+
}
211+
}
212+
213+
struct CustomThemeCreator: View {
214+
@Binding var selectedTheme: DiffTheme
215+
@Environment(\.dismiss) var dismiss
216+
217+
@State private var addedBgColor = Color.green.opacity(0.2)
218+
@State private var addedTextColor = Color.green
219+
@State private var removedBgColor = Color.red.opacity(0.2)
220+
@State private var removedTextColor = Color.red
221+
222+
var body: some View {
223+
NavigationView {
224+
Form {
225+
Section("Added Lines") {
226+
ColorPicker("Background", selection: $addedBgColor)
227+
ColorPicker("Text", selection: $addedTextColor)
228+
}
229+
230+
Section("Removed Lines") {
231+
ColorPicker("Background", selection: $removedBgColor)
232+
ColorPicker("Text", selection: $removedTextColor)
233+
}
234+
235+
Section("Preview") {
236+
DiffRenderer(diffText: """
237+
diff --git a/test.swift b/test.swift
238+
@@ -1,3 +1,3 @@
239+
-let oldValue = "Hello"
240+
+let newValue = "World"
241+
let unchanged = true
242+
""")
243+
.diffTheme(customTheme)
244+
.frame(height: 100)
245+
}
246+
}
247+
.navigationTitle("Create Custom Theme")
248+
.navigationBarTitleDisplayMode(.inline)
249+
.toolbar {
250+
ToolbarItem(placement: .navigationBarLeading) {
251+
Button("Cancel") { dismiss() }
252+
}
253+
ToolbarItem(placement: .navigationBarTrailing) {
254+
Button("Apply") {
255+
selectedTheme = customTheme
256+
dismiss()
257+
}
258+
}
259+
}
260+
}
261+
}
262+
263+
private var customTheme: DiffTheme {
264+
DiffTheme(
265+
addedBackground: addedBgColor,
266+
addedText: addedTextColor,
267+
removedBackground: removedBgColor,
268+
removedText: removedTextColor,
269+
contextBackground: Color.gray.opacity(0.1),
270+
contextText: Color.primary,
271+
lineNumberBackground: Color.gray.opacity(0.1),
272+
lineNumberText: Color.secondary,
273+
headerBackground: Color.blue.opacity(0.1),
274+
headerText: Color.blue,
275+
fileHeaderBackground: Color.gray.opacity(0.1),
276+
fileHeaderText: Color.primary
277+
)
278+
}
279+
}
280+
281+
#Preview {
282+
ThemeGalleryView()
283+
}

0 commit comments

Comments
 (0)