Using internal enabled var for cell instead of label enabled state

This commit is contained in:
vasavk 2024-06-14 21:20:11 +05:30
parent b8326faa16
commit 4119a6c180

View File

@ -47,7 +47,6 @@ final class CalendarDateViewCell: UICollectionViewCell {
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
@ -56,6 +55,7 @@ final class CalendarDateViewCell: UICollectionViewCell {
}
}
private var isEnabled = false
private lazy var shapeLayer = CAShapeLayer()
private var surface: Surface = .light
private let selectedTextColorConfiguration = SurfaceColorConfiguration(VDSColor.elementsPrimaryInverseOnlight, VDSColor.elementsPrimaryInverseOndark)
@ -135,20 +135,21 @@ final class CalendarDateViewCell: UICollectionViewCell {
}
}
// update text color, bg color, corner radius.
if numberLabel.text == selectedDate.getDay()
&& selectedDate.monthInt == displayDate.monthInt
&& selectedDate.yearInt == displayDate.yearInt
&& numberLabel.isEnabled {
numberLabel.textColor = selectedTextColorConfiguration.getColor(surface)
layer.backgroundColor = selectedBackgroundColor.getColor(surface).cgColor
layer.cornerRadius = VDSFormControls.borderRadius
} else {
numberLabel.textColor = unselectedTextColorConfiguration.getColor(surface)
layer.backgroundColor = nil
layer.cornerRadius = 0
// Set selected/unselected state text color, bg color, corner radius if cell is in enabled state.
if isEnabled {
if numberLabel.text == selectedDate.getDay()
&& selectedDate.monthInt == displayDate.monthInt
&& selectedDate.yearInt == displayDate.yearInt {
numberLabel.textColor = selectedTextColorConfiguration.getColor(surface)
layer.backgroundColor = selectedBackgroundColor.getColor(surface).cgColor
layer.cornerRadius = VDSFormControls.borderRadius
} else {
numberLabel.textColor = unselectedTextColorConfiguration.getColor(surface)
layer.backgroundColor = nil
layer.cornerRadius = 0
}
}
// add indicators.
@ -177,11 +178,11 @@ final class CalendarDateViewCell: UICollectionViewCell {
// returns cell enabled state.
func isDateEnabled() -> Bool {
return numberLabel.isEnabled
return isEnabled
}
func disableLabel(with surface: Surface) {
numberLabel.isEnabled = false
isEnabled = false
numberLabel.textColor = disabledTextColorConfiguration.getColor(surface)
layer.backgroundColor = disabledBackgroundColor.getColor(surface).cgColor
}
@ -190,7 +191,7 @@ final class CalendarDateViewCell: UICollectionViewCell {
for x in 0...activeDates.count-1 {
if activeDates[x].monthInt == displayDate.monthInt && activeDates[x].yearInt == displayDate.yearInt {
if let day:Int = Int(numberLabel.text), day == activeDates[x].dayInt {
numberLabel.isEnabled = true
isEnabled = true
}
}
}
@ -201,7 +202,7 @@ final class CalendarDateViewCell: UICollectionViewCell {
if activeDates.count > 0 && inactiveDates.count == 0 {
showActiveDates(with: displayDate, activeDates: activeDates, inactiveDates: inactiveDates)
} else {
numberLabel.isEnabled = true
isEnabled = true
}
}
@ -211,7 +212,7 @@ final class CalendarDateViewCell: UICollectionViewCell {
disableLabel(with: surface)
showActiveDates(with: displayDate, activeDates: activeDates, inactiveDates: inactiveDates)
} else {
numberLabel.isEnabled = true
isEnabled = true
}
}
@ -220,7 +221,7 @@ final class CalendarDateViewCell: UICollectionViewCell {
if let day = Int(numberLabel.text), day < minDate.dayInt {
disableLabel(with: surface)
} else {
numberLabel.isEnabled = false
isEnabled = false
handleActiveDates(with: displayDate, activeDates: activeDates, inactiveDates: inactiveDates)
}
}
@ -230,7 +231,7 @@ final class CalendarDateViewCell: UICollectionViewCell {
if let day = Int(numberLabel.text), day > maxDate.dayInt {
disableLabel(with: surface)
} else {
numberLabel.isEnabled = false
isEnabled = false
handleActiveDates(with: displayDate, activeDates: activeDates, inactiveDates: inactiveDates)
}
}
@ -240,7 +241,7 @@ final class CalendarDateViewCell: UICollectionViewCell {
if let day = Int(numberLabel.text), day < minDate.dayInt || day > maxDate.dayInt {
disableLabel(with: surface)
} else {
numberLabel.isEnabled = false
isEnabled = false
handleActiveDates(with: displayDate, activeDates: activeDates, inactiveDates: inactiveDates)
}
}