From 20f5926bbf6ad810f605adb4e54998a75a111bdf Mon Sep 17 00:00:00 2001 From: vasavk Date: Fri, 10 May 2024 13:18:55 +0530 Subject: [PATCH] Digital ACT-191 ONEAPP-7958 story: callback when the date changes and is in enabled state only. --- VDS/Components/Calendar/Calendar.swift | 27 ++++++++++++------- .../Calendar/CalendarDateViewCell.swift | 5 ++++ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/VDS/Components/Calendar/Calendar.swift b/VDS/Components/Calendar/Calendar.swift index fa843db0..bcba3885 100644 --- a/VDS/Components/Calendar/Calendar.swift +++ b/VDS/Components/Calendar/Calendar.swift @@ -287,17 +287,24 @@ extension CalendarBase: UICollectionViewDelegate, UICollectionViewDataSource, UI } public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { - let selectedItem = Calendar.current.date(byAdding: .day, value: 1, to: self.dates[indexPath.row])! - onChangeSelectedDate?(selectedItem) - - selectedDate = self.dates[indexPath.row] - displayDate = selectedDate - var reloadIndexPaths = [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 { + // 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) + + selectedDate = self.dates[indexPath.row] + displayDate = selectedDate + var reloadIndexPaths = [indexPath] - // If an cell is already selected, then it needs to be deselected. - // Add its index path to the array of index paths to be reloaded. - if let deselectIndexPath = selectedIndexPath { reloadIndexPaths.append(deselectIndexPath) } - self.collectionView.reloadItems(at: reloadIndexPaths) + // If an cell is already selected, then it needs to be deselected. + // Add its index path to the array of index paths to be reloaded. + if let deselectIndexPath = selectedIndexPath { reloadIndexPaths.append(deselectIndexPath) } + self.collectionView.reloadItems(at: reloadIndexPaths) + } + } } public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize { diff --git a/VDS/Components/Calendar/CalendarDateViewCell.swift b/VDS/Components/Calendar/CalendarDateViewCell.swift index 7bbe3fd0..26886d0a 100644 --- a/VDS/Components/Calendar/CalendarDateViewCell.swift +++ b/VDS/Components/Calendar/CalendarDateViewCell.swift @@ -147,6 +147,11 @@ final class CalendarDateViewCell: UICollectionViewCell { } } + // returns cell enabled state. + func isDateEnabled() -> Bool { + return numberLabel.isEnabled + } + func disableLabel(with surface: Surface) { numberLabel.isEnabled = false numberLabel.textColor = disabledTextColorConfiguration.getColor(surface)