Digital ACT-191 ONEAPP-7958 story: callback when the date changes and is in enabled state only.
This commit is contained in:
parent
6bb6d31b39
commit
20f5926bbf
@ -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 {
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user