Files
Reflect/Shared/Views/SmallRollUpHeaderView.swift
Trey t 7f27446b94 Fix 8 audit items: remove force-unwraps, improve accessibility and concurrency
- Replace force-unwrap HK types with modern HKQuantityType(_:) initializer
- Replace Calendar.date force-unwraps with guard/let in HealthService, HeaderPercView, MoodStreakActivity, DayViewViewModel, MonthTotalTemplate
- Extract DayViewViewModel.countEntries into testable static method with safe flatMap
- Replace DispatchQueue.main.asyncAfter with Task.sleep in CelebrationAnimations
- Add .minimumScaleFactor(0.5) to SmallRollUpHeaderView for Dynamic Type
- Add VoiceOver accessibility labels to HeaderPercView mood percentages
- Fix @testable import iFeel → Feels in Tests_iOS.swift
- Add 4 unit tests for countEntries (TDD)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 11:42:16 -06:00

103 lines
3.4 KiB
Swift

//
// SmallHeaderView.swift
// Feels (iOS)
//
// Created by Trey Tartt on 1/28/22.
//
import SwiftUI
struct SmallRollUpHeaderView: View {
@Binding var viewType: MainSwitchableViewType
@AppStorage(UserDefaultsStore.Keys.moodTint.rawValue, store: GroupUserDefaults.groupDefaults) private var moodTint: MoodTints = .Default
@AppStorage(UserDefaultsStore.Keys.shape.rawValue, store: GroupUserDefaults.groupDefaults) private var shape: BGShape = .circle
@AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system
private var textColor: Color { theme.currentTheme.labelColor }
let entries: [MoodEntryModel]
private var moodMetrics = [MoodMetrics]()
init(entries: [MoodEntryModel], viewType: Binding<MainSwitchableViewType>) {
self.entries = entries
self._viewType = viewType
moodMetrics = Random.createTotalPerc(fromEntries: entries)
}
private func textView(forModel model: MoodMetrics) -> Text {
switch viewType {
case .total:
return Text(String(model.total))
case .percentageShape:
return Text("\(model.percent, specifier: "%.0f")%")
case .percentage:
return Text("\(model.percent, specifier: "%.0f")%")
}
}
private var onlyTextView: some View {
HStack() {
ForEach(moodMetrics, id: \.id) { model in
textView(forModel: model)
.font(.title2)
.fontWeight(.bold)
.lineLimit(1)
.minimumScaleFactor(0.5)
.foregroundColor(moodTint.color(forMood: model.mood))
.frame(maxWidth: .infinity, alignment: .center)
}
}
.frame(maxWidth: .infinity, alignment: .leading)
.padding([.top, .bottom])
}
private var shapeView: some View {
HStack {
ForEach(moodMetrics, id: \.id) { model in
HStack {
shape.view(withText: textView(forModel: model),
bgColor: moodTint.color(forMood: model.mood),
textColor: textColor)
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}
}
.padding([.top, .bottom])
}
private var viewOnViewtype : some View {
HStack {
switch viewType {
case .total, .percentageShape:
shapeView
case .percentage:
onlyTextView
}
}
}
var body: some View {
viewOnViewtype
.frame(maxWidth: .infinity, alignment: .leading)
}
}
struct SmallHeaderView_Previews: PreviewProvider {
static var previews: some View {
Group {
SmallRollUpHeaderView(entries: DataController.shared.randomEntries(count: 10),
viewType: .constant(.total))
SmallRollUpHeaderView(entries: DataController.shared.randomEntries(count: 10),
viewType: .constant(.percentageShape))
.background(.gray)
SmallRollUpHeaderView(entries: DataController.shared.randomEntries(count: 10),
viewType: .constant(.percentage))
.background(.gray)
}
}
}