Repository navigation
Added
CalendarViewDataSource.title(forMonth:), which receives the first day of the
month the header shows. Its default returnsheaderString(_:), so existing
data sources keep their titles.KDCalendarView.displayedMonth(_:), a two-way binding to the month on screen.
The calendar sets it to the first day of each month it settles on, and
assigning a date scrolls to its month, animated insidewithAnimation, even
when the user has swiped away from that month. A month outside the range is
set back to the month on screen.KDCalendarView.mirrorsInRightToLeftLayouts(_:). A SwiftUI calendar can now
mirror in a right-to-left layout, following the layout direction of the
SwiftUI environment. It is off by default, as before.CalendarView.reloadsEventsWhenStoreChanges(KDCalendarEventKit), off by
default. When on, a view that has loaded events loads them again after its
store reports a change, such as an edit in the Calendar app. Changes reported
close together or during a load start one query, and a reload never asks for
calendar access.CalendarEventStore.changeNotification, the notification a store posts when
its events change. It defaults tonil, so existing stores still conform;
EKEventStorereturnsEKEventStoreChanged.- Localisations of the VoiceOver strings in Catalan, Czech, Danish, Dutch,
Finnish, French, German, Greek, Hungarian, Indonesian, Italian, Japanese,
Korean, Norwegian Bokmål, Polish, Portuguese, Romanian, Russian, Spanish,
Swedish, Turkish, Ukrainian and Simplified and Traditional Chinese.
Changed
-
EventsManageris a struct around oneCalendarEventStoreinstead of an enum
of static methods that each took astoreargument.EventsManager.shared
uses the system event store, andEventsManager(store:)another one, such as
a test double.CalendarView.eventsManager,EventsManager.sharedby
default, is the managerloadEvents(),saveEvent(_:)and
addEvent(_:date:duration:)use. -
Every public declaration has a documentation comment, and the lint keeps it
that way. The closures of the SwiftUI modifiers and of
loadEvents(onComplete:)name their parameters, such as
onLongPress(_ action: (_ date: Date, _ events: [CalendarEvent]) -> Void). -
didScrollToMonthis also sent when a reload leaves the calendar on another
month.didDeselectDatefor days a reload drops arrives once the view shows
the whole reload. -
Setting
style,events,marksWeekendsordirectionto the value it
already has no longer reloads. Styles compare by value, and a colour made
withUIColor { traits in ... }equals only itself: the documentation of
CalendarView.Styleexplains how to create such colours once, so that a
style built in a SwiftUIbodydoes not reload the calendar on every update. -
The delegate's
canSelectDate, and theKDCalendarView.canSelect(_:)
predicate, are asked for each day as it is drawn as well as for taps and
selections in code, and again for the days on screen at the layout that
follows a change of the selection, so that VoiceOver knows which days are
refused. Keep them quick and free of side effects, and callreloadData()
when the answers change for another reason than the selection. -
Style.headerHeightandStyle.weekdaysHeightare minimums: the header is
taller when its fonts need more room. -
The weekday labels use the stand-alone weekday symbols, as column headings
do: "Mo" rather than "Mo." in German. -
Setting
eventsno longer asks the calendar about every day of every event.
Twenty events spanning a 100-year range took about 7 seconds to index and now
take well under 0.2 seconds. -
A
KDCalendarViewis set up with one reload, and an update that changes
several modifier values at once (style, range, direction, weekend marking,
events) reloads the calendar once instead of once per value. An update sets
on the calendar only the values that changed since the last one, where it
used to setallowsDeselectionandscrollEnabledevery time. -
KDCalendarView.displayDate(_:)treatsnilas no request, so a date that
followsnilscrolls again, even to the same month as before. -
The log message for an invalid data source range shows its dates instead of
<private>. -
The documentation says more:
calendar(_:didLongPressDate:withEvents:)
states that a long press is reported for days that cannot be selected, such
as days out of range;CalendarEventand itsendDatesay which days an
event marks (an event that ends exactly at midnight does not mark the day
that starts then, and an event with no length still marks its day); and
KDCalendarView.rangesays that its ends are moments, read as days in the
style's calendar at each reload. -
The EventKit bridge keeps a view's manager and load state in one object
instead of three associated objects. No behaviour change.
Deprecated
-
Style.CellShapeOptions,Style.FirstWeekdayOptions,Style.WeekDaysTransform
andStyle.weekDayTransform, renamedStyle.CellShape,Style.FirstWeekday,
Style.WeekdayCasingandStyle.weekdayCasing. The old names still compile,
with a fix-it. -
The static
EventsManager.store,hasFullAccess,load(from:to:store:),
save(_:store:)andadd(event:store:), and thestoreargument of
CalendarView.loadEvents,saveEventandaddEvent. Use
EventsManager.sharedor setCalendarView.eventsManagerinstead. -
CalendarViewDataSource.headerString(_:). Implementtitle(forMonth:)
instead;headerString(_:)will be removed in 3.0.
Fixed
selectRange(_:)dropped the selected days outside the new range without
telling the delegate, and a range with no selectable day emptied the
selection silently. The delegate now receivesdidDeselectDatefor each day
dropped, beforedidSelectRange, as it does when a tap or the selection mode
drops days.- Overlapping
loadEvents()calls assigned their events in the order their
queries finished, so an earlier load, such as one for the range before the
data source changed it, could overwrite a later one. The latest call wins
now: a load that a later one supersedes leaveseventsalone and throws
CancellationError, which the completion form passes to its handler. - An event saved with
saveEvent(_:)oraddEvent(_:date:duration:)while a
loadEvents()query was running lost its dot when the load assigned a result
that did not contain it. The load now keeps the events saved while it ran. - A
KDCalendarViewselection binding applied after the device changed time
zone, but before the calendar reloaded, could select the day before or after
the one shown. The view now computes every date in the calendar its grid is
laid out in until the reload moves the grid, the selection and the month
titles to the new time zone together. - After
reloadData(), or any change that reloads, the calendar stays on the
month it displayed, wherever the new range puts it, and moves to the nearest
month when that month is no longer in range.displayDate, the title and the
scroll position now agree, andgoToNextMonth()andgoToPreviousMonth()
keep working after the range changes. Before, a range that gained earlier
months showed another month under the old title. - Assigning a data source after the first layout displays a month of its range
with the right title. - A time zone change keeps the displayed month, with
displayDateon the first
day of that month in the new zone. - The header title follows a new
style.locale, and the data source's
title(forMonth:)is asked again after every reload. - A vertical calendar stays on its month when the header changes height, with
the text size or withStyle.headerHeight. - Month titles capitalise only their first letter: "Enero de 2024", not "Enero
De 2024". A title that starts with the year is left as the locale writes it,
such as "2024. január". - The month title names the era in calendars that need one to name a year: a
Japanese calendar shows "January Reiwa 6" rather than "January 6", and a
Chinese calendar the year it started in. - The right-to-left layout no longer depends on setting
forceLtrafter
semanticContentAttribute, and follows later changes of the view's layout
direction. - A calendar that is right to left from its first layout opens on its first
month, not its last. - The today marker moves at midnight in
style.calendar, also when that
calendar is in another time zone than the device, and also when the device
slept until then. - A month whose first day has no midnight no longer breaks the grid (for
example October 2023 inAmerica/Asuncion, where daylight saving time starts
at 00:00 on the 1st). Its days were handed out at 01:00 instead of the start
of the day, days of later months resolved to the cells of the month before
(selectDateselected a day a month early), and the last day of the range
was out of range. - Setting
multipleSelectionEnabletotrueleaves.rangemode alone
instead of switching it to.multiple; only.singlebecomes.multiple,
andfalsestill means.single. - A custom
Style.calendarwhose time zone isTimeZone.autoupdatingCurrent,
or whose locale isLocale.autoupdatingCurrent, now follows a change of the
device's settings at the next reload, asCalendar.autoupdatingCurrentdoes.
Until then the grid's dates and the selection no longer drift to the new time
zone. - The header grows to fit its fonts at the larger Dynamic Type sizes instead of
clipping the month title and the weekday labels. - Weekday labels show one-letter names when the short ones do not fit their
columns, and day numbers shrink to fit their cells, instead of truncating or
clipping. - VoiceOver reads "Today" and the number of events in the language of
Style.locale, the language the date is read in, rather than in the app's
language. In a language the library has no strings for, the words are the
app's and the count now takes its plural form by that language's rules, not
the device's. - Days the delegate's
canSelectDaterefuses are announced as dimmed buttons
by VoiceOver, like days out of range. - VoiceOver reads the weekday labels as full weekday names.
KDCalendarView.displayDate(_:)compared instants, so.displayDate(Date())
scrolled back to the current month every time the body ran, undoing the
user's swipes. It now scrolls only when the value moves to another month. The
demo and the README example bind the month withdisplayedMonth(_:)instead.- A
KDCalendarViewselection no longer shifts by a day after the device, or
the style's calendar, moves to another time zone. The selection binding now
follows the view to the new zone's midnights, where it used to keep the old
instants and select the day before on the next update. loadEvents(onComplete:)never called its handler when the view was released
before the load started. The handler is now always called exactly once, with
CancellationErrorin that case.