Skip to content

Commit

Permalink
Continue requiring non-optional value for overlays and ranges since w…
Browse files Browse the repository at this point in the history
…e dont provide a default
  • Loading branch information
calda committed Sep 19, 2023
1 parent 2b69eb8 commit c3a027d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
17 changes: 7 additions & 10 deletions Sources/Internal/VisibleItemsProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -950,13 +950,11 @@ final class VisibleItemsProvider {
daysAndFrames: dayRangeLayoutContext.daysAndFrames,
boundingUnionRectOfDayFrames: dayRangeLayoutContext.boundingUnionRectOfDayFrames)

if let dayRangeItemModel = dayRangeItemProvider(dayRangeLayoutContext) {
context.visibleItems.insert(
VisibleItem(
calendarItemModel: dayRangeItemModel,
itemType: .dayRange(dayRange),
frame: frame))
}
context.visibleItems.insert(
VisibleItem(
calendarItemModel: dayRangeItemProvider(dayRangeLayoutContext),
itemType: .dayRange(dayRange),
frame: frame))
}

private func handlePinnedDaysOfWeekIfNeeded(
Expand Down Expand Up @@ -1031,16 +1029,15 @@ final class VisibleItemsProvider {
let layoutContext = overlayLayoutContext(
for: overlaidItemLocation,
inBounds: bounds,
context: &context),
let itemModel = itemModelProvider(layoutContext)
context: &context)
else
{
continue
}

context.visibleItems.insert(
VisibleItem(
calendarItemModel: itemModel,
calendarItemModel: itemModelProvider(layoutContext),
itemType: .overlayItem(overlaidItemLocation),
frame: bounds))
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/Public/CalendarViewContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public final class CalendarViewContent {
for dateRanges: Set<ClosedRange<Date>>,
_ dayRangeItemProvider: @escaping (
_ dayRangeLayoutContext: DayRangeLayoutContext)
-> AnyCalendarItemModel?)
-> AnyCalendarItemModel)
-> CalendarViewContent
{
let dayRanges = Set(dateRanges.map { DayRange(containing: $0, in: calendar) })
Expand Down Expand Up @@ -366,7 +366,7 @@ public final class CalendarViewContent {
for overlaidItemLocations: Set<OverlaidItemLocation>,
_ overlayItemProvider: @escaping (
_ overlayLayoutContext: OverlayLayoutContext)
-> AnyCalendarItemModel?)
-> AnyCalendarItemModel)
-> CalendarViewContent
{
overlaidItemLocationsAndItemProvider = (overlaidItemLocations, overlayItemProvider)
Expand Down Expand Up @@ -398,10 +398,10 @@ public final class CalendarViewContent {
private(set) var monthBackgroundItemProvider: ((MonthLayoutContext) -> AnyCalendarItemModel?)?
private(set) var dayRangesAndItemProvider: (
dayRanges: Set<DayRange>,
dayRangeItemProvider: (DayRangeLayoutContext) -> AnyCalendarItemModel?)?
dayRangeItemProvider: (DayRangeLayoutContext) -> AnyCalendarItemModel)?
private(set) var overlaidItemLocationsAndItemProvider: (
overlaidItemLocations: Set<OverlaidItemLocation>,
overlayItemProvider: (OverlayLayoutContext) -> AnyCalendarItemModel?)?
overlayItemProvider: (OverlayLayoutContext) -> AnyCalendarItemModel)?

/// The default `monthHeaderItemProvider` if no provider has been configured,
/// or if the existing provider returns nil.
Expand Down
6 changes: 0 additions & 6 deletions Tests/CalendarContentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ final class CalendarContentTests: XCTestCase {
.dayBackgroundItemProvider { _ in
nil
}
.dayRangeItemProvider(for: Set([Date.distantPast...Date.distantFuture])) { _ in
nil
}
.overlayItemProvider(for: Set([.day(containingDate: .distantPast)])) { _ in
nil
}
}

func testNilDayItemUsesDefaultValue() {
Expand Down

0 comments on commit c3a027d

Please sign in to comment.