|
| 1 | +import SwiftUI |
| 2 | +import gitdiff |
| 3 | + |
| 4 | +struct ThemesView: View { |
| 5 | + @State private var selectedTheme: DiffTheme = .github |
| 6 | + |
| 7 | + var body: some View { |
| 8 | + NavigationView { |
| 9 | + VStack { |
| 10 | + ScrollView(.horizontal, showsIndicators: false) { |
| 11 | + HStack(spacing: 12) { |
| 12 | + ThemeButton(theme: .github, label: "GitHub", isSelected: isGitHub) { |
| 13 | + selectedTheme = .github |
| 14 | + } |
| 15 | + ThemeButton(theme: .gitlab, label: "GitLab", isSelected: isGitLab) { |
| 16 | + selectedTheme = .gitlab |
| 17 | + } |
| 18 | + ThemeButton(theme: .vsCodeLight, label: "VS Code Light", isSelected: isVSCodeLight) { |
| 19 | + selectedTheme = .vsCodeLight |
| 20 | + } |
| 21 | + ThemeButton(theme: .vsCodeDark, label: "VS Code Dark", isSelected: isVSCodeDark) { |
| 22 | + selectedTheme = .vsCodeDark |
| 23 | + } |
| 24 | + ThemeButton(theme: .xcodeLight, label: "Xcode Light", isSelected: isXcodeLight) { |
| 25 | + selectedTheme = .xcodeLight |
| 26 | + } |
| 27 | + ThemeButton(theme: .xcodeDark, label: "Xcode Dark", isSelected: isXcodeDark) { |
| 28 | + selectedTheme = .xcodeDark |
| 29 | + } |
| 30 | + } |
| 31 | + .padding() |
| 32 | + } |
| 33 | + |
| 34 | + ScrollView { |
| 35 | + VStack(alignment: .leading, spacing: 20) { |
| 36 | + Text("Theme: \(themeName)") |
| 37 | + .font(.headline) |
| 38 | + .padding(.horizontal) |
| 39 | + |
| 40 | + DiffRenderer(diffText: sampleDiff) |
| 41 | + .diffTheme(selectedTheme) |
| 42 | + .padding() |
| 43 | + } |
| 44 | + } |
| 45 | + } |
| 46 | + .navigationTitle("Themes") |
| 47 | + .navigationBarTitleDisplayMode(.inline) |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + private var themeName: String { |
| 52 | + switch selectedTheme { |
| 53 | + case .github: return "GitHub" |
| 54 | + case .gitlab: return "GitLab" |
| 55 | + case .vsCodeLight: return "VS Code Light" |
| 56 | + case .vsCodeDark: return "VS Code Dark" |
| 57 | + case .xcodeLight: return "Xcode Light" |
| 58 | + case .xcodeDark: return "Xcode Dark" |
| 59 | + default: return "Custom" |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + private var isGitHub: Bool { selectedTheme == .github } |
| 64 | + private var isGitLab: Bool { selectedTheme == .gitlab } |
| 65 | + private var isVSCodeLight: Bool { selectedTheme == .vsCodeLight } |
| 66 | + private var isVSCodeDark: Bool { selectedTheme == .vsCodeDark } |
| 67 | + private var isXcodeLight: Bool { selectedTheme == .xcodeLight } |
| 68 | + private var isXcodeDark: Bool { selectedTheme == .xcodeDark } |
| 69 | + |
| 70 | + private let sampleDiff = """ |
| 71 | + diff --git a/Theme.swift b/Theme.swift |
| 72 | + index 1234567..abcdefg 100644 |
| 73 | + --- a/Theme.swift |
| 74 | + +++ b/Theme.swift |
| 75 | + @@ -5,7 +5,9 @@ struct Theme { |
| 76 | + let primaryColor: Color |
| 77 | + let secondaryColor: Color |
| 78 | + |
| 79 | + - static let light = Theme( |
| 80 | + + /// Light theme with blue accent |
| 81 | + + static let light = Theme( |
| 82 | + primaryColor: .blue, |
| 83 | + - secondaryColor: .gray |
| 84 | + + secondaryColor: .gray, |
| 85 | + + backgroundColor: .white |
| 86 | + ) |
| 87 | + """ |
| 88 | + |
| 89 | + private struct ThemeButton: View { |
| 90 | + let theme: DiffTheme |
| 91 | + let label: String |
| 92 | + let isSelected: Bool |
| 93 | + let action: () -> Void |
| 94 | + |
| 95 | + var body: some View { |
| 96 | + Button(action: action) { |
| 97 | + Text(label) |
| 98 | + .font(.caption) |
| 99 | + .padding(.horizontal, 12) |
| 100 | + .padding(.vertical, 8) |
| 101 | + .background(isSelected ? Color.accentColor : Color(UIColor.systemGray5)) |
| 102 | + .foregroundColor(isSelected ? .white : .primary) |
| 103 | + .cornerRadius(8) |
| 104 | + } |
| 105 | + } |
| 106 | + } |
| 107 | +} |
0 commit comments