Digital ACT-191 ONEAPP-7016 story: config container background, hide/show current date indicator

This commit is contained in:
vasavk 2024-05-06 16:01:56 +05:30
parent e980d816b3
commit 7fe5123a69
2 changed files with 39 additions and 102 deletions

View File

@ -36,7 +36,7 @@ open class CalendarBase: View {
open var hideContainerBorder: Bool = false { didSet { setNeedsUpdate() } } open var hideContainerBorder: Bool = false { didSet { setNeedsUpdate() } }
/// If set to true, the calendar will not have current date indication. /// If set to true, the calendar will not have current date indication.
open var hideCurrentDateIndicator: Bool = false open var hideCurrentDateIndicator: Bool = false { didSet { setNeedsUpdate() } }
/// Enable specific days. Pass an array of string value in date format e.g. ['07/21/2024', '07/24/2024', 07/28/2024']. /// Enable specific days. Pass an array of string value in date format e.g. ['07/21/2024', '07/24/2024', 07/28/2024'].
/// All other dates will be inactive /// All other dates will be inactive
@ -117,10 +117,7 @@ open class CalendarBase: View {
// MARK: - Configuration // MARK: - Configuration
//-------------------------------------------------- //--------------------------------------------------
internal var containerBorderColorConfiguration = SurfaceColorConfiguration(VDSColor.elementsPrimaryOnlight , VDSColor.elementsPrimaryOndark) internal var containerBorderColorConfiguration = SurfaceColorConfiguration(VDSColor.elementsPrimaryOnlight , VDSColor.elementsPrimaryOndark)
internal var backgroundColorConfiguration = ControlColorConfiguration().with { internal var backgroundColorConfiguration = SurfaceColorConfiguration(VDSFormControlsColor.backgroundOnlight, VDSFormControlsColor.backgroundOndark)
$0.setSurfaceColors(VDSFormControlsColor.backgroundOnlight, VDSFormControlsColor.backgroundOndark, forState: .normal)
$0.setSurfaceColors(VDSFormControlsColor.backgroundOnlight, VDSFormControlsColor.backgroundOndark, forState: .disabled)
}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Lifecycle // MARK: - Lifecycle
@ -163,6 +160,7 @@ open class CalendarBase: View {
super.updateView() super.updateView()
self.fetchDates(with: selectedDate) self.fetchDates(with: selectedDate)
collectionView.reloadData() collectionView.reloadData()
layer.backgroundColor = backgroundColorConfiguration.getColor(self).cgColor
if hideContainerBorder { if hideContainerBorder {
layer.borderColor = nil layer.borderColor = nil
layer.borderWidth = 0 layer.borderWidth = 0
@ -230,7 +228,7 @@ extension CalendarBase: UICollectionViewDelegate, UICollectionViewDataSource, UI
} }
} }
} }
cell.configure(with: surface, indicators: indicators, text: days[indexPath.row], indicatorCount: indicatorCount, selectedDate: selectedDate) cell.update(with: surface, indicators: indicators, text: days[indexPath.row], indicatorCount: indicatorCount, selectedDate: selectedDate, hideDate: hideCurrentDateIndicator)
if (self.days[indexPath.row] == self.getDay(with: selectedDate)) { selectedIndexPath = indexPath } if (self.days[indexPath.row] == self.getDay(with: selectedDate)) { selectedIndexPath = indexPath }
return cell return cell
} }

View File

@ -15,66 +15,6 @@ final class CalendarDateCollectionViewCell: UICollectionViewCell {
///Identifier for the Calendar Date Cell ///Identifier for the Calendar Date Cell
static let identifier: String = String(describing: CalendarDateCollectionViewCell.self) static let identifier: String = String(describing: CalendarDateCollectionViewCell.self)
//--------------------------------------------------
// MARK: - Private Properties
//--------------------------------------------------
private lazy var dateView = DateView()
//--------------------------------------------------
// MARK: - Initializers
//--------------------------------------------------
override init(frame: CGRect) {
super.init(frame: frame)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func configure(with surface: Surface, indicators: [CalendarBase.CalendarIndicatorModel], text: String, indicatorCount: Int, selectedDate: Date) {
addSubview(dateView)
dateView.surface = surface
dateView.numberLabel.text = text
dateView.indicatorCount = indicatorCount
dateView.dateIndicators = indicators
dateView.selectedDate = selectedDate
}
}
/// Date view to show Date number and indicator if applies
private class DateView : View {
//--------------------------------------------------
// MARK: - Initializers
//--------------------------------------------------
required public init() {
super.init(frame: .zero)
}
public override init(frame: CGRect) {
super.init(frame: .zero)
}
public required init?(coder: NSCoder) {
super.init(coder: coder)
}
//--------------------------------------------------
// MARK: - Public Properties
//--------------------------------------------------
open var indicatorCount: Int = 0
open var dateIndicators: [CalendarBase.CalendarIndicatorModel] = [] { didSet { setNeedsUpdate() } }
open var numberLabel = Label().with {
$0.translatesAutoresizingMaskIntoConstraints = false
$0.textAlignment = .center
$0.textStyle = .bodySmall
}
open var selectedDate: Date = Date() //? { didSet { setNeedsUpdate() } }
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Private Properties // MARK: - Private Properties
//-------------------------------------------------- //--------------------------------------------------
@ -95,7 +35,13 @@ private class DateView : View {
$0.setContentHuggingPriority(.defaultHigh, for: .horizontal) $0.setContentHuggingPriority(.defaultHigh, for: .horizontal)
} }
}() }()
private var numberLabel = Label().with {
$0.translatesAutoresizingMaskIntoConstraints = false
$0.textAlignment = .center
$0.textStyle = .bodySmall
}
private lazy var shapeLayer = CAShapeLayer() private lazy var shapeLayer = CAShapeLayer()
private let selectedTextColorConfiguration = SurfaceColorConfiguration(VDSColor.elementsPrimaryInverseOnlight, VDSColor.elementsPrimaryInverseOndark) private let selectedTextColorConfiguration = SurfaceColorConfiguration(VDSColor.elementsPrimaryInverseOnlight, VDSColor.elementsPrimaryInverseOndark)
@ -104,20 +50,25 @@ private class DateView : View {
private let unselectedTextColorConfiguration = SurfaceColorConfiguration(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark) private let unselectedTextColorConfiguration = SurfaceColorConfiguration(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark)
private let unselectedCellIndicatorColorConfiguration = SurfaceColorConfiguration(VDSColor.elementsSecondaryOnlight, VDSColor.elementsSecondaryOndark) private let unselectedCellIndicatorColorConfiguration = SurfaceColorConfiguration(VDSColor.elementsSecondaryOnlight, VDSColor.elementsSecondaryOndark)
private let currentDate = Date()
private let currentDate = Date()
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Lifecycle // MARK: - Initializers
//-------------------------------------------------- //--------------------------------------------------
open override func initialSetup() { override init(frame: CGRect) {
super.initialSetup() super.init(frame: frame)
setUp()
} }
open override func setup() { required init?(coder: NSCoder) {
super.setup() super.init(coder: coder)
setUp()
}
private func setUp() {
isAccessibilityElement = false isAccessibilityElement = false
addSubview(containerView) contentView.addSubview(containerView)
containerView containerView
.pinTop() .pinTop()
.pinBottom() .pinBottom()
@ -130,27 +81,27 @@ private class DateView : View {
// Number label // Number label
containerView.addSubview(numberLabel) containerView.addSubview(numberLabel)
numberLabel.pinToSuperView() numberLabel.pinToSuperView()
// Indicators // Indicators
containerView.addSubview(stackView) containerView.addSubview(stackView)
let topPos = containerSize.height * 0.7 let topPos = containerSize.height * 0.7
stackView.pinTop(topPos).pinBottom().pinTopGreaterThanOrEqualTo().pinTrailingLessThanOrEqualTo().pinCenterY() stackView.pinTop(topPos).pinBottom().pinTopGreaterThanOrEqualTo().pinTrailingLessThanOrEqualTo().pinCenterY()
stackView.centerXAnchor.constraint(equalTo: centerXAnchor).activate() stackView.centerXAnchor.constraint(equalTo: centerXAnchor).activate()
} }
open override func updateView() { func update(with surface: Surface, indicators: [CalendarBase.CalendarIndicatorModel], text: String, indicatorCount: Int, selectedDate: Date, hideDate: Bool) {
super.updateView() numberLabel.text = text
numberLabel.surface = surface numberLabel.surface = surface
numberLabel.isEnabled = isEnabled // numberLabel.isEnabled = isEnabled
stackView.arrangedSubviews.forEach { $0.removeFromSuperview() } stackView.arrangedSubviews.forEach { $0.removeFromSuperview() }
// update text color, bg color, corner radius // update text color, bg color, corner radius
if numberLabel.text == self.getDay(with: selectedDate) { if numberLabel.text == self.getDay(with: selectedDate) {
numberLabel.textColor = selectedTextColorConfiguration.getColor(self) numberLabel.textColor = selectedTextColorConfiguration.getColor(surface)
layer.backgroundColor = selectedBackgroundColor.getColor(self).cgColor layer.backgroundColor = selectedBackgroundColor.getColor(surface).cgColor
layer.cornerRadius = VDSFormControls.borderRadius layer.cornerRadius = VDSFormControls.borderRadius
} else { } else {
numberLabel.textColor = unselectedTextColorConfiguration.getColor(self) numberLabel.textColor = unselectedTextColorConfiguration.getColor(surface)
layer.backgroundColor = nil layer.backgroundColor = nil
layer.cornerRadius = 0 layer.cornerRadius = 0
} }
@ -159,34 +110,23 @@ private class DateView : View {
if indicatorCount > 0 { if indicatorCount > 0 {
let width = (indicatorCount * 8) + (Int(VDSLayout.space1X) * (indicatorCount - 1)) let width = (indicatorCount * 8) + (Int(VDSLayout.space1X) * (indicatorCount - 1))
stackView.widthAnchor.constraint(equalToConstant: CGFloat(width)).activate() stackView.widthAnchor.constraint(equalToConstant: CGFloat(width)).activate()
for x in (0...(dateIndicators.count-1)) { for x in (0...(indicators.count-1)) {
if (self.numberLabel.text == self.getDay(with: dateIndicators[x].date)) { if (self.numberLabel.text == self.getDay(with: indicators[x].date)) {
if numberLabel.text == self.getDay(with: selectedDate) { if numberLabel.text == self.getDay(with: selectedDate) {
addIndicator(with: selectedCellIndicatorColorConfiguration.getColor(self), surface: surface, clearFullCircle: (x == 1), drawSemiCircle: (x == 2)) addIndicator(with: selectedCellIndicatorColorConfiguration.getColor(surface), surface: surface, clearFullCircle: (x == 1), drawSemiCircle: (x == 2))
} else { } else {
addIndicator(with: unselectedCellIndicatorColorConfiguration.getColor(self), surface: surface, clearFullCircle: (x == 1), drawSemiCircle: (x == 2)) addIndicator(with: unselectedCellIndicatorColorConfiguration.getColor(surface), surface: surface, clearFullCircle: (x == 1), drawSemiCircle: (x == 2))
} }
} }
} }
} }
// update text style for current date // update text style for current date
if numberLabel.text == self.getDay(with: currentDate) { if (numberLabel.text == self.getDay(with: currentDate)) {
numberLabel.textStyle = .boldBodySmall numberLabel.textStyle = hideDate ? .bodySmall : .boldBodySmall
} else { } else {
numberLabel.textStyle = .bodySmall numberLabel.textStyle = .bodySmall
} }
}
override open func layoutSubviews() {
super.layoutSubviews()
}
open override func reset() {
super.reset()
numberLabel.textStyle = .bodySmall
} }
//-------------------------------------------------- //--------------------------------------------------
@ -235,5 +175,4 @@ private class DateView : View {
return day return day
} }
} }
} }