From 3eaf29f3f1ec7f0c3ef482b99f00c683a4bf6d55 Mon Sep 17 00:00:00 2001 From: vasavk Date: Mon, 6 May 2024 09:47:02 +0530 Subject: [PATCH] Digital ACT-191 ONEAPP-7016 story: hide/show container border --- VDS/Components/Calendar/Calendar.swift | 31 ++++++++++++------- .../Calendar/CalendarReusableView.swift | 8 ----- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/VDS/Components/Calendar/Calendar.swift b/VDS/Components/Calendar/Calendar.swift index 3e1442e1..41890756 100644 --- a/VDS/Components/Calendar/Calendar.swift +++ b/VDS/Components/Calendar/Calendar.swift @@ -33,7 +33,7 @@ open class CalendarBase: View { // MARK: - Public Properties //-------------------------------------------------- /// If set to true, the calendar will not have a border. - open var hideContainerBorder: Bool = false + open var hideContainerBorder: Bool = false { didSet { setNeedsUpdate() } } /// If set to true, the calendar will not have current date indication. open var hideCurrentDateIndicator: Bool = false @@ -123,7 +123,7 @@ open class CalendarBase: View { $0.setSurfaceColors(VDSFormControlsColor.backgroundOnlight, VDSFormControlsColor.backgroundOndark, forState: .normal) $0.setSurfaceColors(VDSFormControlsColor.backgroundOnlight, VDSFormControlsColor.backgroundOndark, forState: .disabled) } - + //-------------------------------------------------- // MARK: - Lifecycle //-------------------------------------------------- @@ -144,9 +144,8 @@ open class CalendarBase: View { .width(containerSize.width) containerView.centerXAnchor.constraint(equalTo: centerXAnchor).activate() - containerView.layer.borderWidth = VDSFormControls.borderWidth - - let spacing = CGFloat(VDSLayout.space2X) //CGFloat(VDSFormControls.spaceInset) // + + let spacing = CGFloat(VDSFormControls.spaceInset) //CGFloat(VDSLayout.space2X) // Calendar View containerView.addSubview(collectionView) @@ -166,7 +165,15 @@ open class CalendarBase: View { super.updateView() self.fetchDates(with: selectedDate ?? Date()) collectionView.reloadData() - containerView.layer.borderColor = containerBorderColorConfiguration.getColor(self).cgColor + if hideContainerBorder { + layer.borderColor = nil + layer.borderWidth = 0 + layer.cornerRadius = 0 + } else { + layer.borderColor = containerBorderColorConfiguration.getColor(self).cgColor + layer.borderWidth = VDSFormControls.borderWidth + layer.cornerRadius = VDSFormControls.borderRadius + } } override open func layoutSubviews() { @@ -220,9 +227,11 @@ extension CalendarBase: UICollectionViewDelegate, UICollectionViewDataSource, UI public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: CalendarDateCollectionViewCell.identifier, for: indexPath) as? CalendarDateCollectionViewCell else { return UICollectionViewCell() } var indicatorCount = 0 - for x in (0...(self.indicators.count-1)) { - if (self.days[indexPath.row] == self.getDay(with: self.indicators[x].date)) { - indicatorCount += 1 + if self.indicators.count > 0 { + for x in (0...(self.indicators.count-1)) { + if (self.days[indexPath.row] == self.getDay(with: self.indicators[x].date)) { + indicatorCount += 1 + } } } cell.configure(with: surface, indicators: indicators, text: days[indexPath.row], indicatorCount: indicatorCount) @@ -251,8 +260,8 @@ extension CalendarBase: UICollectionViewDelegate, UICollectionViewDataSource, UI } public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { - let date = Calendar.current.date(byAdding: .day, value: 1, to: self.dates[indexPath.row])! -// print("selected day: \(days[indexPath.row]), date: \(date)") +// let selectedDate = Calendar.current.date(byAdding: .day, value: 1, to: self.dates[indexPath.row])! +// print("selected day: \(days[indexPath.row]), date: \(selectedDate)") } public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize { diff --git a/VDS/Components/Calendar/CalendarReusableView.swift b/VDS/Components/Calendar/CalendarReusableView.swift index 3a61e635..ebb2d269 100644 --- a/VDS/Components/Calendar/CalendarReusableView.swift +++ b/VDS/Components/Calendar/CalendarReusableView.swift @@ -28,10 +28,6 @@ class CalendarHeaderReusableView: UICollectionReusableView { headerView.surface = surface addSubview(headerView) } - - override func layoutSubviews() { - super.layoutSubviews() - } } /// Custom footer view @@ -55,8 +51,4 @@ class CalendarFooterReusableView: UICollectionReusableView { footerView.surface = surface addSubview(footerView) } - - override func layoutSubviews() { - super.layoutSubviews() - } }