Files
Reflect/Shared/Views/HeaderPercView.swift
Trey t bea2d3bbc9 Update Neon colors and show color circles in theme picker
- Update NeonMoodTint to use synthwave colors matching Neon voting style
  (cyan, lime, yellow, orange, magenta)
- Replace text label with 5 color circles in theme preview Colors row
- Remove unused textColor customization code and picker views
- Add .id(moodTint) to Month/Year views for color refresh
- Clean up various unused color-related code

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-30 00:08:01 -06:00

121 lines
4.0 KiB
Swift

//
// HeaderPercView.swift
// Feels (iOS)
//
// Created by Trey Tartt on 1/29/22.
//
import SwiftUI
enum PercViewType {
case text
case shape
}
struct HeaderPercView: View {
@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 }
@State private var entries = [MoodMetrics]()
let backDays: Int
let type: PercViewType
@MainActor
init(fakeData: Bool, backDays: Int, type: PercViewType) {
self.type = type
self.backDays = backDays
var moodEntries: [MoodEntryModel]?
if fakeData {
moodEntries = DataController.shared.randomEntries(count: 10)
} else {
var daysAgo = Calendar.current.date(byAdding: .day, value: -backDays, to: Date())!
daysAgo = Calendar.current.date(bySettingHour: 0, minute: 0, second: 0, of: daysAgo)!
moodEntries = DataController.shared.getData(startDate: daysAgo, endDate: Date(), includedDays: [1,2,3,4,5,6,7])
}
if let moodEntries = moodEntries {
let moodMetrics = Random.createTotalPerc(fromEntries: moodEntries)
_entries = State(initialValue: moodMetrics.sorted(by: {
$0.mood.rawValue > $1.mood.rawValue
}))
}
}
private var textViews: some View {
VStack {
Spacer()
HStack {
ForEach(entries.prefix(3), id: \.id) { model in
Text("\(model.percent, specifier: "%.0f")%")
.font(.title)
.fontWeight(.bold)
.foregroundColor(moodTint.color(forMood: model.mood))
.frame(maxWidth: .infinity)
}
}
Spacer()
HStack {
ForEach(entries.suffix(2), id: \.id) { model in
Text("\(model.percent, specifier: "%.0f")%")
.font(.title)
.fontWeight(.bold)
.foregroundColor(moodTint.color(forMood: model.mood))
.frame(maxWidth: .infinity)
}
}
Spacer()
}
}
private var shapeViews: some View {
VStack {
Spacer()
HStack {
ForEach(entries.prefix(3), id: \.id) { model in
shape.view(withText: Text("\(model.percent, specifier: "%.0f")%"),
bgColor: moodTint.color(forMood: model.mood),
textColor: textColor)
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}
Spacer()
HStack {
ForEach(entries.suffix(2), id: \.id) { model in
shape.view(withText: Text("\(model.percent, specifier: "%.0f")%"),
bgColor: moodTint.color(forMood: model.mood),
textColor: textColor)
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}
Spacer()
}
.foregroundColor(textColor)
}
var body: some View {
ZStack {
switch self.type {
case .text:
textViews
case .shape:
shapeViews
.padding([.leading, .trailing])
}
}
}
}
struct HeaderPercView_Previews: PreviewProvider {
static var previews: some View {
HeaderPercView(fakeData: true, backDays: 30, type: .text)
HeaderPercView(fakeData: true, backDays: 30, type: .shape)
}
}