From b8326faa161848132331665c15bad99dc966930a Mon Sep 17 00:00:00 2001 From: vasavk Date: Fri, 14 Jun 2024 21:17:48 +0530 Subject: [PATCH] Digital ACT-191 CXTDT-568463 defect: Calendar - On long press, hover randomizes --- VDS/Components/Calendar/Calendar.swift | 48 ++++++++----------- .../Calendar/CalendarDateViewCell.swift | 33 ++++++++----- VDS/SupportingFiles/ReleaseNotes.txt | 2 +- 3 files changed, 40 insertions(+), 43 deletions(-) diff --git a/VDS/Components/Calendar/Calendar.swift b/VDS/Components/Calendar/Calendar.swift index 2b0ba57b..3dbf0ba1 100644 --- a/VDS/Components/Calendar/Calendar.swift +++ b/VDS/Components/Calendar/Calendar.swift @@ -201,7 +201,7 @@ open class CalendarBase: Control, Changeable { } } updateViewConstraints() - } + } func updateViewConstraints() { collectionView.reloadData() @@ -331,38 +331,28 @@ 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] - sendActions(for: .valueChanged) - 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) + let hasDate: Bool = cell.hasText() + if hasDate { + let isEnabled: Bool = cell.isDateEnabled() + if isEnabled { + // Callback to pass selected date if it is enabled only. + selectedDate = dates[indexPath.row] + sendActions(for: .valueChanged) + 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) + } + + collectionView.reloadItems(at: reloadIndexPaths) } - - collectionView.reloadItems(at: reloadIndexPaths) } } } diff --git a/VDS/Components/Calendar/CalendarDateViewCell.swift b/VDS/Components/Calendar/CalendarDateViewCell.swift index 4b6f400d..ee2f01c9 100644 --- a/VDS/Components/Calendar/CalendarDateViewCell.swift +++ b/VDS/Components/Calendar/CalendarDateViewCell.swift @@ -41,6 +41,21 @@ final class CalendarDateViewCell: UICollectionViewCell { $0.textStyle = .bodySmall } + override var isHighlighted: Bool { + didSet{ + if self.isHighlighted && hasText() && isDateEnabled() { + self.contentView.layer.borderColor = activeBorderColorConfiguration.getColor(surface).cgColor + self.contentView.layer.borderWidth = VDSFormControls.borderWidth + self.contentView.layer.cornerRadius = VDSFormControls.borderRadius + + } else { + self.contentView.layer.borderColor = nil + self.contentView.layer.borderWidth = 0 + self.contentView.layer.cornerRadius = 0 + } + } + } + private lazy var shapeLayer = CAShapeLayer() private var surface: Surface = .light private let selectedTextColorConfiguration = SurfaceColorConfiguration(VDSColor.elementsPrimaryInverseOnlight, VDSColor.elementsPrimaryInverseOndark) @@ -155,24 +170,16 @@ final class CalendarDateViewCell: UICollectionViewCell { numberLabel.textStyle = .bodySmall } } - + + func hasText() -> Bool { + return !numberLabel.text.isEmpty + } + // returns cell enabled state. func isDateEnabled() -> Bool { 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) diff --git a/VDS/SupportingFiles/ReleaseNotes.txt b/VDS/SupportingFiles/ReleaseNotes.txt index 326146fb..a3772a7b 100644 --- a/VDS/SupportingFiles/ReleaseNotes.txt +++ b/VDS/SupportingFiles/ReleaseNotes.txt @@ -1,6 +1,6 @@ 1.0.67 ---------------- -- CXTDT-553663 - DropdownSelect - Accessibility - has popup +- CXTDT-568463 - Calendar - On long press, hover randomizes 1.0.66 ----------------