- Wrap 30+ production print() statements in #if DEBUG guards across 18 files - Add VoiceOver labels, hints, and traits to Watch app, Live Activities, widgets - Add .accessibilityAddTraits(.isButton) to 15+ onTapGesture views - Add text alternatives for color-only indicators (progress dots, mood circles) - Localize raw string literals in NoteEditorView, EntryDetailView, widgets - Replace 25+ silent try? with do/catch + AppLogger error logging - Replace hardcoded font sizes with semantic Dynamic Type fonts - Fix FIXME in IconPickerView (log icon change errors) - Extract magic animation delays to named constants across 8 files - Add widget empty state "Log your first mood!" messaging - Hide decorative images from VoiceOver, add labels to ColorPickers - Remove stale TODO in Color+Codable (alpha change deferred for migration) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
115 lines
4.0 KiB
Swift
115 lines
4.0 KiB
Swift
//
|
|
// SwitchableView.swift
|
|
// Reflect (iOS)
|
|
//
|
|
// Created by Trey Tartt on 1/30/22.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
enum MainSwitchableViewType: Int, CaseIterable {
|
|
case total
|
|
case percentageShape
|
|
case percentage
|
|
|
|
func next() -> MainSwitchableViewType {
|
|
let currentValue = self.rawValue
|
|
var next = currentValue + 1
|
|
if next == MainSwitchableViewType.allCases.count {
|
|
next = 0
|
|
}
|
|
return MainSwitchableViewType(rawValue: next) ?? .total
|
|
}
|
|
}
|
|
|
|
struct SwitchableView: View {
|
|
@Binding var viewType: MainSwitchableViewType
|
|
var headerTypeChanged: ((MainSwitchableViewType) -> Void)
|
|
let daysBack: Int
|
|
|
|
@AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system
|
|
@AppStorage(UserDefaultsStore.Keys.moodTint.rawValue, store: GroupUserDefaults.groupDefaults) private var moodTint: MoodTints = .Default
|
|
|
|
private var textColor: Color { theme.currentTheme.labelColor }
|
|
|
|
init(daysBack: Int, viewType: Binding<MainSwitchableViewType>, headerTypeChanged: @escaping ((MainSwitchableViewType) -> Void)) {
|
|
self.daysBack = daysBack
|
|
self.headerTypeChanged = headerTypeChanged
|
|
self._viewType = viewType
|
|
}
|
|
|
|
private var mainViews: some View {
|
|
switch viewType {
|
|
case .total:
|
|
return AnyView(
|
|
HeaderStatsView(fakeData: false, backDays: daysBack, moodTint: [
|
|
moodTint.color(forMood: .great),
|
|
moodTint.color(forMood: .good),
|
|
moodTint.color(forMood: .average),
|
|
moodTint.color(forMood: .bad),
|
|
moodTint.color(forMood: .horrible)
|
|
], textColor: textColor))
|
|
.allowsHitTesting(false)
|
|
case .percentageShape:
|
|
return AnyView(
|
|
HeaderPercView(fakeData: false, backDays: daysBack, type: .shape))
|
|
.allowsHitTesting(false)
|
|
case .percentage:
|
|
return AnyView(
|
|
HeaderPercView(fakeData: false, backDays: daysBack, type: .text))
|
|
.allowsHitTesting(false)
|
|
}
|
|
}
|
|
|
|
var body: some View {
|
|
VStack {
|
|
ZStack {
|
|
mainViews
|
|
.padding([.top, .bottom])
|
|
|
|
VStack {
|
|
HStack {
|
|
Spacer()
|
|
Image(systemName: "arrow.triangle.2.circlepath.circle")
|
|
.resizable()
|
|
.frame(width: 20, height: 20, alignment: .trailing)
|
|
}
|
|
Spacer()
|
|
}
|
|
.padding(.trailing, 8)
|
|
.padding(.top, 12)
|
|
.allowsHitTesting(false)
|
|
.foregroundColor(Color(UIColor.systemGray))
|
|
}
|
|
.padding(.top, -7)
|
|
|
|
Text(String(format: String(localized: "content_view_header_title"), daysBack))
|
|
.font(.body)
|
|
.foregroundColor(Color(UIColor.systemGray))
|
|
.frame(maxWidth: .infinity, alignment: .center)
|
|
.padding(.top, -12)
|
|
}
|
|
.background(
|
|
theme.currentTheme.secondaryBGColor
|
|
)
|
|
.contentShape(Rectangle())
|
|
.accessibilityIdentifier(AccessibilityID.SwitchableView.headerToggle)
|
|
.cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
|
|
.padding(.bottom, 30)
|
|
.onTapGesture {
|
|
viewType = viewType.next()
|
|
self.headerTypeChanged(viewType)
|
|
AnalyticsManager.shared.track(.viewHeaderChanged(header: String(describing: viewType)))
|
|
}
|
|
.accessibilityAddTraits(.isButton)
|
|
.accessibilityLabel(String(localized: "Switch header view"))
|
|
}
|
|
}
|
|
|
|
struct SwitchableView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
SwitchableView(daysBack: 30, viewType: .constant(.total), headerTypeChanged: { _ in
|
|
})
|
|
}
|
|
}
|