Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add view builder closures for custom views #268

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Head Lead of Developer Enablement


### 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