Skip to content

Commit 3087f5e

Browse files
Refactor color handling and UI components for adaptive design
- Removed hardcoded color schemes in multiple views, replacing them with adaptive colors from AppColors. - Updated ContentView, ModelCardView, NotepadView, and various onboarding steps to use AppColors for text and background styles. - Added a new AppTab enum for managing tab selection in the iOS app. - Introduced a new network client entitlement in the app's entitlements file. - Ensured that the app respects the system's light/dark mode settings across various views.
1 parent 34b2242 commit 3087f5e

28 files changed

+208
-118
lines changed

Playground/YapRun/YapRun/ContentView.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ struct ContentView: View {
5454
Text(viewModel.errorMessage ?? "")
5555
}
5656
}
57-
.preferredColorScheme(.dark)
5857
}
5958

6059
// MARK: - Header
@@ -154,10 +153,10 @@ struct ContentView: View {
154153
if let label = actionLabel, let action {
155154
Button(label, action: action)
156155
.font(.caption.weight(.semibold))
157-
.foregroundStyle(.white)
156+
.foregroundStyle(AppColors.textPrimary)
158157
.padding(.horizontal, 12)
159158
.padding(.vertical, 6)
160-
.background(Color.white.opacity(0.12), in: Capsule())
159+
.background(AppColors.overlayMedium, in: Capsule())
161160
}
162161
}
163162
.padding(14)
@@ -223,7 +222,7 @@ struct ContentView: View {
223222
.foregroundStyle(AppColors.textSecondary)
224223
.padding(.horizontal, 10)
225224
.padding(.vertical, 6)
226-
.background(Color.white.opacity(0.08), in: Capsule())
225+
.background(AppColors.overlayLight, in: Capsule())
227226
}
228227
}
229228

Playground/YapRun/YapRun/Core/AppColors.swift

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// YapRun
44
//
55
// Brand color palette for YapRun.
6-
// Identity: black background, white as the primary voice.
6+
// All colors are adaptive — they flip between light and dark mode automatically.
77
//
88

99
import SwiftUI
@@ -18,29 +18,55 @@ extension Color {
1818
opacity: alpha
1919
)
2020
}
21+
22+
/// Adaptive color that switches between light and dark appearances.
23+
init(light: Color, dark: Color) {
24+
#if os(iOS)
25+
self.init(uiColor: UIColor { traits in
26+
traits.userInterfaceStyle == .dark ? UIColor(dark) : UIColor(light)
27+
})
28+
#elseif os(macOS)
29+
self.init(nsColor: NSColor(name: nil) { appearance in
30+
appearance.bestMatch(from: [.darkAqua, .aqua]) == .darkAqua
31+
? NSColor(dark) : NSColor(light)
32+
})
33+
#endif
34+
}
2135
}
2236

2337
struct AppColors {
24-
// Primary — white on black
25-
static let primaryAccent = Color.white
38+
// Primary accent — adapts to theme
39+
static let primaryAccent = Color.primary
2640
static let primaryGreen = Color(hex: 0x10B981)
2741
static let primaryRed = Color(hex: 0xEF4444)
2842

2943
// CTA
3044
static let ctaOrange = Color(hex: 0xF59E0B)
3145

32-
// Backgrounds — dark theme
33-
static let backgroundPrimaryDark = Color(hex: 0x000000)
34-
static let backgroundSecondaryDark = Color(hex: 0x0D0D0D)
35-
static let backgroundTertiaryDark = Color(hex: 0x1A1A1A)
36-
static let backgroundGray5Dark = Color(hex: 0x242424)
46+
// Backgrounds — adaptive
47+
static let backgroundPrimary = Color(light: Color(hex: 0xFFFFFF), dark: Color(hex: 0x000000))
48+
static let backgroundSecondary = Color(light: Color(hex: 0xF2F2F7), dark: Color(hex: 0x0D0D0D))
49+
static let backgroundTertiary = Color(light: Color(hex: 0xE5E5EA), dark: Color(hex: 0x1A1A1A))
50+
static let backgroundGray5 = Color(light: Color(hex: 0xD1D1D6), dark: Color(hex: 0x242424))
51+
52+
// Cards — adaptive
53+
static let cardBackground = Color(light: Color(hex: 0xFFFFFF), dark: Color(hex: 0x141414))
54+
static let cardBorder = Color.primary.opacity(0.08)
55+
56+
// Text hierarchy — adaptive (use .primary / .secondary for most cases)
57+
static let textPrimary = Color.primary
58+
static let textSecondary = Color.secondary
59+
static let textTertiary = Color.primary.opacity(0.4)
3760

38-
// Cards
39-
static let cardBackground = Color(hex: 0x141414)
40-
static let cardBorder = Color.white.opacity(0.08)
61+
// Subtle overlays — adaptive (used for button backgrounds, dividers)
62+
static let overlayThin = Color.primary.opacity(0.06)
63+
static let overlayLight = Color.primary.opacity(0.08)
64+
static let overlayMedium = Color.primary.opacity(0.12)
65+
static let overlayThick = Color.primary.opacity(0.15)
4166

42-
// Text hierarchy
43-
static let textPrimary = Color.white
44-
static let textSecondary = Color.white.opacity(0.6)
45-
static let textTertiary = Color.white.opacity(0.4)
67+
// Legacy aliases (kept to minimize churn, map to adaptive versions)
68+
static let backgroundPrimaryDark = backgroundPrimary
69+
static let backgroundSecondaryDark = backgroundSecondary
70+
static let backgroundTertiaryDark = backgroundTertiary
71+
static let backgroundGray5Dark = backgroundGray5
4672
}

Playground/YapRun/YapRun/Core/AppTypes.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ enum MicPermissionState: String {
6262
}
6363
}
6464

65+
// MARK: - App Tab (iOS tab bar)
66+
67+
enum AppTab: String {
68+
case home
69+
case playground
70+
case notepad
71+
}
72+
6573
// MARK: - Hub Section (macOS sidebar)
6674

6775
enum HubSection: String, CaseIterable, Identifiable {

Playground/YapRun/YapRun/Features/Home/AddModelURLSheet.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,5 @@ struct AddModelURLSheet: View {
6161
}
6262
}
6363
}
64-
.preferredColorScheme(.dark)
6564
}
6665
}

Playground/YapRun/YapRun/Features/Home/ModelCardView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ struct ModelCardView: View {
8585
Button(action: onLoad) {
8686
Text("Load")
8787
.font(.caption.weight(.semibold))
88-
.foregroundStyle(.white)
88+
.foregroundStyle(AppColors.textPrimary)
8989
.padding(.horizontal, 12)
9090
.padding(.vertical, 6)
91-
.background(Color.white.opacity(0.12), in: Capsule())
91+
.background(AppColors.overlayMedium, in: Capsule())
9292
}
9393

9494
Button(action: onDelete) {

Playground/YapRun/YapRun/Features/Notepad/NotepadView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ struct NotepadView: View {
8888
.font(.system(size: 14))
8989
.foregroundStyle(AppColors.textSecondary)
9090
.frame(width: 32, height: 32)
91-
.background(Color.white.opacity(0.08), in: Circle())
91+
.background(AppColors.overlayLight, in: Circle())
9292
}
9393
.disabled(text.isEmpty)
9494
.opacity(text.isEmpty ? 0.4 : 1)
@@ -100,7 +100,7 @@ struct NotepadView: View {
100100
.font(.system(size: 14))
101101
.foregroundStyle(AppColors.textSecondary)
102102
.frame(width: 32, height: 32)
103-
.background(Color.white.opacity(0.08), in: Circle())
103+
.background(AppColors.overlayLight, in: Circle())
104104
}
105105
.disabled(text.isEmpty)
106106
.opacity(text.isEmpty ? 0.4 : 1)

Playground/YapRun/YapRun/Features/Onboarding/OnboardingView.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct OnboardingView: View {
5252
}
5353
}
5454
.animation(.easeInOut(duration: 0.25), value: viewModel.currentStep)
55-
.preferredColorScheme(.dark)
55+
// Respects system light/dark mode
5656
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in
5757
viewModel.refreshStatus()
5858
}
@@ -97,7 +97,7 @@ struct OnboardingView: View {
9797
.padding(.horizontal, 10)
9898
.padding(.vertical, 6)
9999
.background(
100-
(isReady ? AppColors.primaryGreen : Color.white).opacity(0.08),
100+
(isReady ? AppColors.primaryGreen : Color.primary).opacity(0.08),
101101
in: Capsule()
102102
)
103103
}
@@ -112,7 +112,7 @@ private struct PageDotIndicator: View {
112112
HStack(spacing: 8) {
113113
ForEach(OnboardingViewModel.Step.allCases, id: \.rawValue) { step in
114114
Capsule()
115-
.fill(step == current ? Color.white : Color.white.opacity(0.25))
115+
.fill(step == current ? Color.primary : Color.primary.opacity(0.25))
116116
.frame(width: step == current ? 24 : 8, height: 8)
117117
.animation(.easeInOut(duration: 0.25), value: current)
118118
}

Playground/YapRun/YapRun/Features/Onboarding/Steps/KeyboardSetupStepView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ struct KeyboardSetupStepView: View {
111111
.foregroundStyle(.black)
112112
.frame(maxWidth: .infinity)
113113
.padding(.vertical, 16)
114-
.background(AppColors.textPrimary, in: Capsule())
114+
.background(AppColors.ctaOrange, in: Capsule())
115115
}
116116

117117
Button {

Playground/YapRun/YapRun/Features/Onboarding/Steps/MicPermissionStepView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ struct MicPermissionStepView: View {
7070
.foregroundStyle(.black)
7171
.frame(maxWidth: .infinity)
7272
.padding(.vertical, 16)
73-
.background(AppColors.textPrimary, in: Capsule())
73+
.background(AppColors.ctaOrange, in: Capsule())
7474
}
7575

7676
Button {

Playground/YapRun/YapRun/Features/Onboarding/Steps/ModelDownloadStepView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct ModelDownloadStepView: View {
5353
.foregroundStyle(.black)
5454
.frame(maxWidth: .infinity)
5555
.padding(.vertical, 16)
56-
.background(AppColors.textPrimary, in: Capsule())
56+
.background(AppColors.ctaOrange, in: Capsule())
5757
}
5858

5959
if viewModel.downloadError != nil {

0 commit comments

Comments
 (0)