From 8fb424bed9b66070b12d0ed829a32663ab9309de Mon Sep 17 00:00:00 2001 From: vasavk Date: Tue, 14 May 2024 15:23:07 +0530 Subject: [PATCH] Digital ACT-191 ONEAPP-7958 story: added active state to highlight date in selecting date --- VDS/Components/Calendar/Calendar.swift | 12 ++++++++++++ .../Calendar/CalendarDateViewCell.swift | 17 +++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/VDS/Components/Calendar/Calendar.swift b/VDS/Components/Calendar/Calendar.swift index 9ec8e6fc..ff137004 100644 --- a/VDS/Components/Calendar/Calendar.swift +++ b/VDS/Components/Calendar/Calendar.swift @@ -296,11 +296,23 @@ extension CalendarBase: UICollectionViewDelegate, UICollectionViewDataSource, UI return UICollectionReusableView() } + + 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. let selectedItem = Calendar.current.date(byAdding: .day, value: 1, to: self.dates[indexPath.row])! onChangeSelectedDate?(selectedItem) diff --git a/VDS/Components/Calendar/CalendarDateViewCell.swift b/VDS/Components/Calendar/CalendarDateViewCell.swift index 26886d0a..29bcb730 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() //-------------------------------------------------- @@ -100,6 +100,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. self.updateLabel(with:surface, displayDate: displayDate, minDate: minDate, maxDate: maxDate, activeDates: activeDates, inactiveDates: inactiveDates) @@ -152,6 +153,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)