anzeige korrigiert Kopfzeilen Monat
This commit is contained in:
@@ -108,23 +108,16 @@ struct MonthView: View {
|
|||||||
cal.date(from: cal.dateComponents([.yearForWeekOfYear, .weekOfYear], from: date))!
|
cal.date(from: cal.dateComponents([.yearForWeekOfYear, .weekOfYear], from: date))!
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Determine the visible month from the currently-scrolled week.
|
/// Determine the header month from the currently-scrolled week.
|
||||||
/// Instead of switching as soon as a few days of the next month appear,
|
/// Rule: take the month of the topmost visible week's start day. This
|
||||||
/// we count the month affiliation of the visible week rows and keep the
|
/// means as long as the "1." of the next month is still visible in the
|
||||||
/// month that occupies the majority of the viewport.
|
/// top row, the header keeps showing the previous month – and only flips
|
||||||
|
/// to the new month once its "1." has scrolled out of view above.
|
||||||
private func publishVisibleMonth(from week: Date?) {
|
private func publishVisibleMonth(from week: Date?) {
|
||||||
guard let w = week else { return }
|
guard let w = week else { return }
|
||||||
|
let month = cal.date(from: cal.dateComponents([.year, .month], from: w)) ?? w
|
||||||
let visibleWeeks = (0..<6).compactMap { cal.date(byAdding: .weekOfYear, value: $0, to: w) }
|
if visibleMonth != month {
|
||||||
let monthCounts = visibleWeeks.reduce(into: [Date: Int]()) { acc, weekStart in
|
visibleMonth = month
|
||||||
guard let midWeek = cal.date(byAdding: .day, value: 3, to: weekStart) else { return }
|
|
||||||
let month = cal.date(from: cal.dateComponents([.year, .month], from: midWeek)) ?? midWeek
|
|
||||||
acc[month, default: 0] += 1
|
|
||||||
}
|
|
||||||
|
|
||||||
let selectedMonth = monthCounts.max { a, b in a.value < b.value }?.key
|
|
||||||
if let m = selectedMonth, visibleMonth != m {
|
|
||||||
visibleMonth = m
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user