Digital ACT-191 ONEAPP-7958 story: dynamic height update for calendar
This commit is contained in:
parent
20f5926bbf
commit
843c8054ad
@ -74,8 +74,9 @@ open class CalendarBase: View {
|
||||
private let headerHeight = 88.0
|
||||
private let footerHeight = 40.0
|
||||
private let calendarWidth = 304.0
|
||||
private let items = 35
|
||||
|
||||
|
||||
private var heightConstraint: NSLayoutConstraint?
|
||||
private var containerHeightConstraint: NSLayoutConstraint?
|
||||
private var selectedIndexPath : IndexPath?
|
||||
private var dates: [Date] = []
|
||||
private var days: [String] = []
|
||||
@ -121,15 +122,16 @@ open class CalendarBase: View {
|
||||
/// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations.
|
||||
open override func setup() {
|
||||
super.setup()
|
||||
isAccessibilityElement = false
|
||||
isAccessibilityElement = true
|
||||
accessibilityLabel = "Calendar"
|
||||
addSubview(containerView)
|
||||
containerView
|
||||
.pinTop()
|
||||
.pinBottom()
|
||||
.pinLeadingGreaterThanOrEqualTo()
|
||||
.pinTrailingLessThanOrEqualTo()
|
||||
.height(containerSize.height)
|
||||
.width(containerSize.width)
|
||||
.heightGreaterThanEqualTo(containerSize.height)
|
||||
containerView.centerXAnchor.constraint(equalTo: centerXAnchor).activate()
|
||||
|
||||
// Calendar View
|
||||
@ -142,10 +144,10 @@ open class CalendarBase: View {
|
||||
.pinLeading(spacing)
|
||||
.pinTrailing(spacing)
|
||||
.width(calendarWidth)
|
||||
.height(calendarHeight)
|
||||
.heightGreaterThanEqualTo(calendarHeight)
|
||||
collectionView.centerXAnchor.constraint(equalTo: containerView.centerXAnchor).activate()
|
||||
}
|
||||
|
||||
|
||||
open override func updateView() {
|
||||
super.updateView()
|
||||
// range check between min & max dates
|
||||
@ -154,8 +156,8 @@ open class CalendarBase: View {
|
||||
let fallsBetween = displayDate.isBetweeen(date: minDate, andDate: maxDate)
|
||||
displayDate = fallsBetween ? displayDate : minDate
|
||||
self.fetchDates(with: displayDate)
|
||||
collectionView.reloadData()
|
||||
}
|
||||
|
||||
layer.backgroundColor = backgroundColorConfiguration.getColor(self).cgColor
|
||||
if hideContainerBorder {
|
||||
layer.borderColor = nil
|
||||
@ -187,6 +189,8 @@ open class CalendarBase: View {
|
||||
// MARK: - Private Methods
|
||||
//--------------------------------------------------
|
||||
func fetchDates(with aDate:Date) {
|
||||
heightConstraint?.isActive = false
|
||||
containerHeightConstraint?.isActive = false
|
||||
days.removeAll()
|
||||
self.dates = aDate.calendarDisplayDays
|
||||
for date in dates {
|
||||
@ -197,6 +201,14 @@ open class CalendarBase: View {
|
||||
days.append(getDay(with: date))
|
||||
}
|
||||
}
|
||||
self.collectionView.reloadData()
|
||||
var height = self.collectionView.collectionViewLayout.collectionViewContentSize.height
|
||||
height = (height > 0) ? height : containerSize.height
|
||||
heightConstraint = collectionView.heightAnchor.constraint(equalToConstant: height)
|
||||
containerHeightConstraint = containerView.heightAnchor.constraint(equalToConstant: (height + (2 * VDSLayout.space4X)))
|
||||
heightConstraint?.isActive = true
|
||||
containerHeightConstraint?.isActive = true
|
||||
self.layoutIfNeeded()
|
||||
}
|
||||
|
||||
func getDay(with date:Date) -> String {
|
||||
@ -259,7 +271,6 @@ extension CalendarBase: UICollectionViewDelegate, UICollectionViewDataSource, UI
|
||||
if ((aDate.monthInt <= maxDate.monthInt) && (aDate.yearInt == maxDate.yearInt)) || (aDate.yearInt < maxDate.yearInt) {
|
||||
displayDate = aDate
|
||||
self.fetchDates(with: displayDate)
|
||||
self.collectionView.reloadData()
|
||||
}
|
||||
}
|
||||
header.previousClicked = { [weak self] in
|
||||
@ -268,7 +279,6 @@ extension CalendarBase: UICollectionViewDelegate, UICollectionViewDataSource, UI
|
||||
if ((minDate.monthInt <= aDate.monthInt) && (minDate.yearInt == aDate.yearInt)) || (minDate.yearInt < aDate.yearInt) {
|
||||
displayDate = aDate
|
||||
self.fetchDates(with: displayDate)
|
||||
self.collectionView.reloadData()
|
||||
}
|
||||
}
|
||||
header.update(with: surface, aDate: displayDate, nextEnabled: nextEnabled, previousEnabled: prevEnabled)
|
||||
|
||||
@ -92,7 +92,9 @@ extension Date {
|
||||
|
||||
/// Check if the date falls between the given dates
|
||||
func isBetweeen(date date1: Date, andDate date2: Date) -> Bool {
|
||||
return date1.compare(self) == self.compare(date2)
|
||||
let from = Calendar.current.date(byAdding: .day, value: -1, to: date1)!
|
||||
let to = Calendar.current.date(byAdding: .day, value: 1, to: date2)!
|
||||
return from.compare(self) == self.compare(to)
|
||||
}
|
||||
|
||||
/// Returns the month name of the given date
|
||||
|
||||
Loading…
Reference in New Issue
Block a user