diff --git a/VDS/Components/Calendar/Calendar.swift b/VDS/Components/Calendar/Calendar.swift index 1b1a797c..f7c1940c 100644 --- a/VDS/Components/Calendar/Calendar.swift +++ b/VDS/Components/Calendar/Calendar.swift @@ -164,15 +164,15 @@ open class CalendarBase: Control, Changeable { fetchDates(with: displayDate) } - layer.backgroundColor = backgroundColorConfiguration.getColor(self).cgColor + containerView.layer.backgroundColor = backgroundColorConfiguration.getColor(self).cgColor if hideContainerBorder { - layer.borderColor = nil - layer.borderWidth = 0 - layer.cornerRadius = 0 + containerView.layer.borderColor = nil + containerView.layer.borderWidth = 0 + containerView.layer.cornerRadius = 0 } else { - layer.borderColor = containerBorderColorConfiguration.getColor(self).cgColor - layer.borderWidth = VDSFormControls.borderWidth - layer.cornerRadius = VDSFormControls.borderRadius + containerView.layer.borderColor = containerBorderColorConfiguration.getColor(self).cgColor + containerView.layer.borderWidth = VDSFormControls.borderWidth + containerView.layer.cornerRadius = VDSFormControls.borderRadius } } @@ -317,11 +317,23 @@ extension CalendarBase: UICollectionViewDelegate, UICollectionViewDataSource, UI } } + + public func collectionView(_ collectionView: UICollectionView, shouldHighlightItemAt indexPath: IndexPath) -> Bool { + if let cell = collectionView.cellForItem(at: indexPath) as? CalendarDateViewCell { + let isEnabled: Bool = cell.isDateEnabled() + if isEnabled { + cell.activeModeStart() + } + } + return true + } + public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { // reload selected index, if it is in enabled state. if let cell = collectionView.cellForItem(at: indexPath) as? CalendarDateViewCell { let isEnabled: Bool = cell.isDateEnabled() if isEnabled { + cell.activeModeEnd() // Callback to pass selected date if it is enabled only. selectedDate = dates[indexPath.row] diff --git a/VDS/Components/Calendar/CalendarDateViewCell.swift b/VDS/Components/Calendar/CalendarDateViewCell.swift index b9f7359b..d66522d0 100644 --- a/VDS/Components/Calendar/CalendarDateViewCell.swift +++ b/VDS/Components/Calendar/CalendarDateViewCell.swift @@ -42,7 +42,7 @@ final class CalendarDateViewCell: UICollectionViewCell { } private lazy var shapeLayer = CAShapeLayer() - + private var surface: Surface = .light private let selectedTextColorConfiguration = SurfaceColorConfiguration(VDSColor.elementsPrimaryInverseOnlight, VDSColor.elementsPrimaryInverseOndark) private let selectedBackgroundColor = SurfaceColorConfiguration(VDSColor.backgroundPrimaryInverseLight, VDSColor.backgroundPrimaryInverseDark) private let selectedCellIndicatorColorConfiguration = SurfaceColorConfiguration(VDSColor.paletteGray65, VDSColor.paletteGray44) @@ -50,7 +50,7 @@ final class CalendarDateViewCell: UICollectionViewCell { private let unselectedCellIndicatorColorConfiguration = SurfaceColorConfiguration(VDSColor.elementsSecondaryOnlight, VDSColor.elementsSecondaryOndark) private let disabledTextColorConfiguration = SurfaceColorConfiguration(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark) private let disabledBackgroundColor = SurfaceColorConfiguration(VDSFormControlsColor.backgroundOnlight, VDSFormControlsColor.backgroundOndark) - + private var activeBorderColorConfiguration = SurfaceColorConfiguration(VDSFormControlsColor.borderHoverOnlight , VDSFormControlsColor.borderHoverOndark) private let currentDate = Date() //-------------------------------------------------- @@ -104,6 +104,7 @@ final class CalendarDateViewCell: UICollectionViewCell { stackView.arrangedSubviews.forEach { $0.removeFromSuperview() } numberLabel.surface = surface numberLabel.text = text + self.surface = surface // enable/disable cells based on min date, max date and active/inactive dates. updateLabel(with:surface, displayDate: displayDate, minDate: minDate, maxDate: maxDate, activeDates: activeDates, inactiveDates: inactiveDates) @@ -160,6 +161,18 @@ final class CalendarDateViewCell: UICollectionViewCell { return numberLabel.isEnabled } + func activeModeStart() { + numberLabel.layer.borderColor = activeBorderColorConfiguration.getColor(surface).cgColor + numberLabel.layer.borderWidth = VDSFormControls.borderWidth + numberLabel.layer.cornerRadius = VDSFormControls.borderRadius + } + + func activeModeEnd() { + numberLabel.layer.borderColor = nil + numberLabel.layer.borderWidth = 0 + numberLabel.layer.cornerRadius = 0 + } + func disableLabel(with surface: Surface) { numberLabel.isEnabled = false numberLabel.textColor = disabledTextColorConfiguration.getColor(surface)