Files
Reflect/Shared/Views/CustomizeView/SubViews/ThemePickerView.swift
Trey T ed8205cd88 Complete accessibility identifier coverage across all 152 project files
Exhaustive file-by-file audit of every Swift file in the project (iOS app,
Watch app, Widget extension). Every interactive UI element — buttons, toggles,
pickers, links, menus, tap gestures, text editors, color pickers, photo
pickers — now has an accessibilityIdentifier for XCUITest automation.

46 files changed across Shared/, Onboarding/, Watch App/, and Widget targets.
Added ~100 new ID definitions covering settings debug controls, export/photo
views, sharing templates, customization subviews, onboarding flows, tip
modals, widget voting buttons, and watch mood buttons.
2026-03-26 08:34:56 -05:00

82 lines
2.4 KiB
Swift

//
// ThemePicker.swift
// Reflect (iOS)
//
// Created by Trey Tartt on 4/2/22.
//
import SwiftUI
struct ThemePickerView: View {
@Environment(\.colorScheme) var colorScheme
@State private var selectedTheme: Theme = UserDefaultsStore.theme()
private var textColor: Color { selectedTheme.currentTheme.labelColor }
var body: some View {
VStack {
HStack(spacing: 0) {
themeButton(for: .system)
themeButton(for: .iFeel)
themeButton(for: .dark)
themeButton(for: .light)
}
.padding(.top)
}
.padding()
.background(selectedTheme.currentTheme.secondaryBGColor)
.fixedSize(horizontal: false, vertical: true)
.cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
.onAppear {
selectedTheme = UserDefaultsStore.theme()
}
}
@ViewBuilder
private func themeButton(for theme: Theme) -> some View {
Button {
selectTheme(theme)
} label: {
VStack {
theme.currentTheme.preview
.allowsHitTesting(false)
.overlay(
Circle()
.stroke(Color(UIColor.systemGray), style: StrokeStyle(lineWidth: 2))
)
Text(theme.title)
.foregroundColor(textColor)
.font(.body)
}
.frame(maxWidth: .infinity)
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.background(
RoundedRectangle(cornerRadius: 10, style: .continuous)
.fill(selectedTheme == theme ? selectedTheme.currentTheme.bgColor : .clear)
.padding(-5)
)
.accessibilityIdentifier(AccessibilityID.Customize.themeButton(theme.title))
}
private func selectTheme(_ theme: Theme) {
// Save theme value
GroupUserDefaults.groupDefaults.set(theme.rawValue, forKey: UserDefaultsStore.Keys.theme.rawValue)
GroupUserDefaults.groupDefaults.synchronize()
withAnimation(.easeInOut(duration: 0.2)) {
selectedTheme = theme
}
AnalyticsManager.shared.track(.themeChanged(themeId: theme.rawValue))
}
}
struct ThemePickerView_Previews: PreviewProvider {
static var previews: some View {
ThemePickerView()
}
}