commit 81ff77b0ece339aa779e0c406fd21921a456526a
parent a8bb9785d28fe7c4703d8707e62bfdc4dc11b8b9
Author: Michael Camilleri <[email protected]>
Date: Fri, 23 Oct 2026 11:35:21 +0900
Update the timeline's current day when the date changes
The timeline marks today's header in the accent colour, but the check
only runs when the header is drawn. If the view hierarchy is not
regenerated, the timeline can show accent colours on both today and
yesterday's header.
This commit stores the current day in the timeline and resets it
whenever the system posts a significant time change, which happens at
midnight, on a time zone change, and on returning to the foreground
after either. Day headers compare against this stored day, so a change
redraws them. The check that hides the year for days in the current
year uses the same day.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat
| M | Reportage/Views/Home/HomeView.swift | | | 20 | +++++++++++++++----- |
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/Reportage/Views/Home/HomeView.swift b/Reportage/Views/Home/HomeView.swift
@@ -195,6 +195,10 @@ private struct ReportDays: View {
let onReachEnd: () -> Void
@SectionedFetchRequest private var days: SectionedFetchResults<String, ReportEntity>
+ /// The current day, for marking its header. A list left open overnight
+ /// isn't redrawn on its own, so this moves on at midnight, or when the
+ /// app returns after one.
+ @State private var today = Date()
init(
start: ListStart, describer: ReportDescriber,
@@ -243,7 +247,7 @@ private struct ReportDays: View {
.listRowSeparatorTint(Theme.rule)
}
} header: {
- DayHeader(date: day.first?.date)
+ DayHeader(date: day.first?.date, today: today)
}
}
if case .date = start {
@@ -262,6 +266,11 @@ private struct ReportDays: View {
.scrollContentBackground(.hidden)
.tabBarClearance()
.background(Theme.paper)
+ .task {
+ for await _ in NotificationCenter.default.notifications(named: UIApplication.significantTimeChangeNotification) {
+ today = Date()
+ }
+ }
}
/// A report is tapped to see it in full, where it can be edited or
@@ -352,11 +361,12 @@ struct NewReportMenu: View {
struct DayHeader: View {
let date: Date?
+ let today: Date
var body: some View {
if let date {
- Text(date, format: Self.format(for: date))
- .eyebrow(Calendar.current.isDateInToday(date) ? Theme.accent : Theme.muted)
+ Text(date, format: Self.format(for: date, now: today))
+ .eyebrow(Calendar.current.isDate(date, inSameDayAs: today) ? Theme.accent : Theme.muted)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.horizontal, Theme.margin)
.padding(.top, Theme.headingTop)
@@ -369,10 +379,10 @@ struct DayHeader: View {
extension DayHeader {
/// The year is only shown for days in another year.
- static func format(for date: Date) -> Date.FormatStyle {
+ static func format(for date: Date, now: Date = Date()) -> Date.FormatStyle {
let style = Date.FormatStyle().weekday(.wide).day().month(.wide)
let calendar = Calendar.current
- return calendar.isDate(date, equalTo: Date(), toGranularity: .year) ? style : style.year()
+ return calendar.isDate(date, equalTo: now, toGranularity: .year) ? style : style.year()
}
}