Skip to content

Commit

Permalink
Add view builder closures for custom views (#268)
Browse files Browse the repository at this point in the history
  • Loading branch information
bryankeller authored Sep 18, 2023
1 parent 2c843d7 commit 7f237b5
Show file tree
Hide file tree
Showing 3 changed files with 206 additions and 39 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added a `multiDaySelectionDragHandler`, enabling developers to implement multiple-day-selection via a drag gesture (similar to multi-select in the iOS Photos app)
- Added the ability to change the aspect ratio of individual day-of-the-week items
- Added support for self-sizing month headers
- Added a new `setContent(_:animated:)` function, allowing people to perform animated content updates
- Added a new `setContent(_:animated:)` function, enabling developers to perform animated content updates

### Fixed
- Fixed an issue that could cause the calendar to programmatically scroll to a month or day to which it had previously scrolled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,32 +96,24 @@ struct SwiftUIScreenDemo: View {
.verticalDayMargin(8)
.horizontalDayMargin(8)

.monthHeaderItemProvider { month in
.monthHeaders { month in
let monthHeaderText = monthDateFormatter.string(from: calendar.date(from: month.components)!)
if case .vertical = monthsLayout {
return HStack {
HStack {
Text(monthHeaderText)
.font(.title2)
Spacer()
}
.padding()
.calendarItemModel
} else {
return Text(monthHeaderText)
Text(monthHeaderText)
.font(.title2)
.padding()
.calendarItemModel
}
}

.dayItemProvider { day in
let isSelected: Bool
if let selectedDayRange {
isSelected = day == selectedDayRange.lowerBound || day == selectedDayRange.upperBound
} else {
isSelected = false
}
return SwiftUIDayView(dayNumber: day.day, isSelected: isSelected).calendarItemModel
.days { day in
SwiftUIDayView(dayNumber: day.day, isSelected: isDaySelected(day))
}

.dayRangeItemProvider(for: selectedDateRanges) { dayRangeLayoutContext in
Expand Down Expand Up @@ -172,7 +164,6 @@ struct SwiftUIScreenDemo: View {
}

.frame(maxWidth: 375, maxHeight: .infinity)

}

// MARK: Private
Expand All @@ -195,6 +186,14 @@ struct SwiftUIScreenDemo: View {
return [selectedStartDate...selectedEndDate]
}

private func isDaySelected(_ day: Day) -> Bool {
if let selectedDayRange {
return day == selectedDayRange.lowerBound || day == selectedDayRange.upperBound
} else {
return false
}
}

}

// MARK: - SwiftUIScreenDemo_Previews
Expand Down
Loading

0 comments on commit 7f237b5

Please sign in to comment.