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:
@@ -20,7 +20,6 @@ struct SplashView: View {
|
||||
.scaleEffect(calendarScale)
|
||||
.opacity(calendarOpacity)
|
||||
|
||||
// Wordmark: kisaniCAL.
|
||||
VStack(spacing: 1) {
|
||||
Text("kisani")
|
||||
.font(AppFonts.mono(11, weight: .regular))
|
||||
@@ -63,55 +62,30 @@ struct SplashView: View {
|
||||
private struct SplashCalendarCard: View {
|
||||
@Environment(\.colorScheme) private var cs
|
||||
|
||||
private let cal = Calendar.current
|
||||
private let today = Calendar.current.component(.day, from: Date())
|
||||
private let monthName: String = {
|
||||
let fmt = DateFormatter(); fmt.dateFormat = "MMMM"
|
||||
return fmt.string(from: Date())
|
||||
private static let cal = Calendar.current
|
||||
private static let today = cal.component(.day, from: Date())
|
||||
private static let monthFmt: DateFormatter = {
|
||||
let f = DateFormatter(); f.dateFormat = "MMMM"; return f
|
||||
}()
|
||||
|
||||
// Flat day array: nil = empty cell, Int = day number
|
||||
private var days: [Int?] {
|
||||
private static var days: [Int?] {
|
||||
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 lead = cal.component(.weekday, from: first) - 1
|
||||
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) }
|
||||
return grid
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 0) {
|
||||
// Month label
|
||||
Text(monthName.uppercased())
|
||||
.font(AppFonts.mono(9, weight: .bold))
|
||||
.foregroundColor(AppColors.text3(cs))
|
||||
.kerning(2)
|
||||
.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)
|
||||
}
|
||||
}
|
||||
}
|
||||
monthHeader
|
||||
Spacer().frame(height: 10)
|
||||
weekdayRow
|
||||
Spacer().frame(height: 6)
|
||||
dayGrid
|
||||
}
|
||||
.padding(.horizontal, 18)
|
||||
.padding(.vertical, 16)
|
||||
@@ -122,11 +96,64 @@ private struct SplashCalendarCard: View {
|
||||
RoundedRectangle(cornerRadius: 20)
|
||||
.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 struct DayCell: View {
|
||||
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
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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 isToday: Bool
|
||||
let cs: ColorScheme
|
||||
@@ -140,7 +167,8 @@ private struct DayCell: View {
|
||||
}
|
||||
if let d = day {
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user