Digital ACT-191 ONEAPP-7958 story: callback when the date changes and is in enabled state only.

This commit is contained in:
vasavk 2024-05-10 13:18:55 +05:30
parent 6bb6d31b39
commit 20f5926bbf
2 changed files with 22 additions and 10 deletions

View File

@ -287,17 +287,24 @@ extension CalendarBase: UICollectionViewDelegate, UICollectionViewDataSource, UI
} }
public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let selectedItem = Calendar.current.date(byAdding: .day, value: 1, to: self.dates[indexPath.row])! // reload selected index, if it is in enabled state.
onChangeSelectedDate?(selectedItem) if let cell = collectionView.cellForItem(at: indexPath) as? CalendarDateViewCell {
let isEnabled: Bool = cell.isDateEnabled()
selectedDate = self.dates[indexPath.row] if isEnabled {
displayDate = selectedDate // Callback to pass selected date if it is enabled only.
var reloadIndexPaths = [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]
// If an cell is already selected, then it needs to be deselected. // 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. // Add its index path to the array of index paths to be reloaded.
if let deselectIndexPath = selectedIndexPath { reloadIndexPaths.append(deselectIndexPath) } if let deselectIndexPath = selectedIndexPath { reloadIndexPaths.append(deselectIndexPath) }
self.collectionView.reloadItems(at: reloadIndexPaths) self.collectionView.reloadItems(at: reloadIndexPaths)
}
}
} }
public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize { public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {

View File

@ -147,6 +147,11 @@ final class CalendarDateViewCell: UICollectionViewCell {
} }
} }
// returns cell enabled state.
func isDateEnabled() -> Bool {
return numberLabel.isEnabled
}
func disableLabel(with surface: Surface) { func disableLabel(with surface: Surface) {
numberLabel.isEnabled = false numberLabel.isEnabled = false
numberLabel.textColor = disabledTextColorConfiguration.getColor(surface) numberLabel.textColor = disabledTextColorConfiguration.getColor(surface)