fix: resolve SplashView type-check timeout and DayCell redeclaration

Break SplashCalendarCard body into monthHeader/weekdayRow/dayGrid
computed vars and extract SplashWeekRow to help the type-checker.
Rename DayCell -> SplashDayCell to avoid collision with CalendarView.
This commit is contained in:
kutesir
2026-05-28 00:38:34 +03:00
parent 21bbde8980
commit d33a3d0168

View File

@@ -20,7 +20,6 @@ struct SplashView: View {
.scaleEffect(calendarScale) .scaleEffect(calendarScale)
.opacity(calendarOpacity) .opacity(calendarOpacity)
// Wordmark: kisaniCAL.
VStack(spacing: 1) { VStack(spacing: 1) {
Text("kisani") Text("kisani")
.font(AppFonts.mono(11, weight: .regular)) .font(AppFonts.mono(11, weight: .regular))
@@ -63,55 +62,30 @@ struct SplashView: View {
private struct SplashCalendarCard: View { private struct SplashCalendarCard: View {
@Environment(\.colorScheme) private var cs @Environment(\.colorScheme) private var cs
private let cal = Calendar.current private static let cal = Calendar.current
private let today = Calendar.current.component(.day, from: Date()) private static let today = cal.component(.day, from: Date())
private let monthName: String = { private static let monthFmt: DateFormatter = {
let fmt = DateFormatter(); fmt.dateFormat = "MMMM" let f = DateFormatter(); f.dateFormat = "MMMM"; return f
return fmt.string(from: Date())
}() }()
// Flat day array: nil = empty cell, Int = day number private static var days: [Int?] {
private var days: [Int?] {
let now = Date() let now = Date()
let range = cal.range(of: .day, in: .month, for: now)!.count let count = cal.range(of: .day, in: .month, for: now)!.count
let first = cal.date(from: cal.dateComponents([.year, .month], from: now))! let first = cal.date(from: cal.dateComponents([.year, .month], from: now))!
let lead = cal.component(.weekday, from: first) - 1 let lead = cal.component(.weekday, from: first) - 1
var grid: [Int?] = Array(repeating: nil, count: lead) var grid: [Int?] = Array(repeating: nil, count: lead)
grid += (1...range).map { Optional($0) } grid += (1...count).map { Optional($0) }
while grid.count % 7 != 0 { grid.append(nil) } while grid.count % 7 != 0 { grid.append(nil) }
return grid return grid
} }
var body: some View { var body: some View {
VStack(spacing: 0) { VStack(spacing: 0) {
// Month label monthHeader
Text(monthName.uppercased()) Spacer().frame(height: 10)
.font(AppFonts.mono(9, weight: .bold)) weekdayRow
.foregroundColor(AppColors.text3(cs)) Spacer().frame(height: 6)
.kerning(2) dayGrid
.padding(.bottom, 10)
// Day-of-week header
HStack(spacing: 0) {
ForEach(Array(["S","M","T","W","T","F","S"].enumerated()), id: \.offset) { _, d in
Text(d)
.font(AppFonts.mono(7.5, weight: .bold))
.foregroundColor(AppColors.text3(cs))
.frame(maxWidth: .infinity)
}
}
.padding(.bottom, 6)
// Day grid
let rowCount = days.count / 7
ForEach(0..<rowCount, id: \.self) { row in
HStack(spacing: 0) {
ForEach(0..<7, id: \.self) { col in
let day = days[row * 7 + col]
DayCell(day: day, isToday: day == today, cs: cs)
}
}
}
} }
.padding(.horizontal, 18) .padding(.horizontal, 18)
.padding(.vertical, 16) .padding(.vertical, 16)
@@ -122,11 +96,64 @@ private struct SplashCalendarCard: View {
RoundedRectangle(cornerRadius: 20) RoundedRectangle(cornerRadius: 20)
.stroke(AppColors.border(cs), lineWidth: 1) .stroke(AppColors.border(cs), lineWidth: 1)
) )
.shadow(color: Color.black.opacity(cs == .dark ? 0.3 : 0.06), radius: 24, y: 8) .shadow(
color: Color.black.opacity(cs == .dark ? 0.3 : 0.06),
radius: 24, y: 8
)
}
private var monthHeader: some View {
Text(Self.monthFmt.string(from: Date()).uppercased())
.font(AppFonts.mono(9, weight: .bold))
.foregroundColor(AppColors.text3(cs))
.kerning(2)
}
private var weekdayRow: some View {
let letters = ["S","M","T","W","T","F","S"]
return HStack(spacing: 0) {
ForEach(0..<7, id: \.self) { i in
Text(letters[i])
.font(AppFonts.mono(7.5, weight: .bold))
.foregroundColor(AppColors.text3(cs))
.frame(maxWidth: .infinity)
}
}
}
private var dayGrid: some View {
let rows = Self.days.count / 7
return VStack(spacing: 0) {
ForEach(0..<rows, id: \.self) { row in
SplashWeekRow(
days: Array(Self.days[(row * 7)..<(row * 7 + 7)]),
today: Self.today,
cs: cs
)
}
}
} }
} }
private struct DayCell: View { // MARK: - Week Row
private struct SplashWeekRow: View {
let days: [Int?]
let today: Int
let cs: ColorScheme
var body: some View {
HStack(spacing: 0) {
ForEach(0..<7, id: \.self) { col in
SplashDayCell(day: days[col], isToday: days[col] == today, cs: cs)
}
}
}
}
// MARK: - Day Cell
private struct SplashDayCell: View {
let day: Int? let day: Int?
let isToday: Bool let isToday: Bool
let cs: ColorScheme let cs: ColorScheme
@@ -140,7 +167,8 @@ private struct DayCell: View {
} }
if let d = day { if let d = day {
Text("\(d)") Text("\(d)")
.font(AppFonts.mono(isToday ? 10 : 9.5, weight: isToday ? .bold : .regular)) .font(AppFonts.mono(isToday ? 10 : 9.5,
weight: isToday ? .bold : .regular))
.foregroundColor(isToday ? .white : AppColors.text(cs).opacity(0.72)) .foregroundColor(isToday ? .white : AppColors.text(cs).opacity(0.72))
} }
} }