Digital ACT-191 ONEAPP-7958 story: added active state to highlight date in selecting date
This commit is contained in:
parent
d06be6f85d
commit
8fb424bed9
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user