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