Digital ACT-191 ONEAPP-7016 story: hide/show container border

This commit is contained in:
vasavk 2024-05-06 09:47:02 +05:30
parent f043ac74d3
commit 3eaf29f3f1
2 changed files with 20 additions and 19 deletions

View File

@ -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 {

View File

@ -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()
}
}