Digital ACT-191 ONEAPP-7016 story: config container background, hide/show current date indicator
This commit is contained in:
parent
e980d816b3
commit
7fe5123a69
@ -36,7 +36,7 @@ open class CalendarBase: View {
|
||||
open var hideContainerBorder: Bool = false { didSet { setNeedsUpdate() } }
|
||||
|
||||
/// 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'].
|
||||
/// All other dates will be inactive
|
||||
@ -117,10 +117,7 @@ open class CalendarBase: View {
|
||||
// MARK: - Configuration
|
||||
//--------------------------------------------------
|
||||
internal var containerBorderColorConfiguration = SurfaceColorConfiguration(VDSColor.elementsPrimaryOnlight , VDSColor.elementsPrimaryOndark)
|
||||
internal var backgroundColorConfiguration = ControlColorConfiguration().with {
|
||||
$0.setSurfaceColors(VDSFormControlsColor.backgroundOnlight, VDSFormControlsColor.backgroundOndark, forState: .normal)
|
||||
$0.setSurfaceColors(VDSFormControlsColor.backgroundOnlight, VDSFormControlsColor.backgroundOndark, forState: .disabled)
|
||||
}
|
||||
internal var backgroundColorConfiguration = SurfaceColorConfiguration(VDSFormControlsColor.backgroundOnlight, VDSFormControlsColor.backgroundOndark)
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Lifecycle
|
||||
@ -163,6 +160,7 @@ open class CalendarBase: View {
|
||||
super.updateView()
|
||||
self.fetchDates(with: selectedDate)
|
||||
collectionView.reloadData()
|
||||
layer.backgroundColor = backgroundColorConfiguration.getColor(self).cgColor
|
||||
if hideContainerBorder {
|
||||
layer.borderColor = nil
|
||||
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 }
|
||||
return cell
|
||||
}
|
||||
|
||||
@ -15,66 +15,6 @@ final class CalendarDateCollectionViewCell: UICollectionViewCell {
|
||||
///Identifier for the Calendar Date Cell
|
||||
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
|
||||
//--------------------------------------------------
|
||||
@ -95,7 +35,13 @@ private class DateView : View {
|
||||
$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 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 unselectedCellIndicatorColorConfiguration = SurfaceColorConfiguration(VDSColor.elementsSecondaryOnlight, VDSColor.elementsSecondaryOndark)
|
||||
|
||||
private let currentDate = Date()
|
||||
|
||||
private let currentDate = Date()
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Lifecycle
|
||||
// MARK: - Initializers
|
||||
//--------------------------------------------------
|
||||
open override func initialSetup() {
|
||||
super.initialSetup()
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
setUp()
|
||||
}
|
||||
|
||||
open override func setup() {
|
||||
super.setup()
|
||||
required init?(coder: NSCoder) {
|
||||
super.init(coder: coder)
|
||||
setUp()
|
||||
}
|
||||
|
||||
private func setUp() {
|
||||
isAccessibilityElement = false
|
||||
addSubview(containerView)
|
||||
contentView.addSubview(containerView)
|
||||
containerView
|
||||
.pinTop()
|
||||
.pinBottom()
|
||||
@ -130,27 +81,27 @@ private class DateView : View {
|
||||
// Number label
|
||||
containerView.addSubview(numberLabel)
|
||||
numberLabel.pinToSuperView()
|
||||
|
||||
|
||||
// Indicators
|
||||
containerView.addSubview(stackView)
|
||||
let topPos = containerSize.height * 0.7
|
||||
stackView.pinTop(topPos).pinBottom().pinTopGreaterThanOrEqualTo().pinTrailingLessThanOrEqualTo().pinCenterY()
|
||||
stackView.centerXAnchor.constraint(equalTo: centerXAnchor).activate()
|
||||
}
|
||||
|
||||
open override func updateView() {
|
||||
super.updateView()
|
||||
|
||||
func update(with surface: Surface, indicators: [CalendarBase.CalendarIndicatorModel], text: String, indicatorCount: Int, selectedDate: Date, hideDate: Bool) {
|
||||
numberLabel.text = text
|
||||
numberLabel.surface = surface
|
||||
numberLabel.isEnabled = isEnabled
|
||||
// numberLabel.isEnabled = isEnabled
|
||||
stackView.arrangedSubviews.forEach { $0.removeFromSuperview() }
|
||||
|
||||
|
||||
// update text color, bg color, corner radius
|
||||
if numberLabel.text == self.getDay(with: selectedDate) {
|
||||
numberLabel.textColor = selectedTextColorConfiguration.getColor(self)
|
||||
layer.backgroundColor = selectedBackgroundColor.getColor(self).cgColor
|
||||
numberLabel.textColor = selectedTextColorConfiguration.getColor(surface)
|
||||
layer.backgroundColor = selectedBackgroundColor.getColor(surface).cgColor
|
||||
layer.cornerRadius = VDSFormControls.borderRadius
|
||||
} else {
|
||||
numberLabel.textColor = unselectedTextColorConfiguration.getColor(self)
|
||||
numberLabel.textColor = unselectedTextColorConfiguration.getColor(surface)
|
||||
layer.backgroundColor = nil
|
||||
layer.cornerRadius = 0
|
||||
}
|
||||
@ -159,34 +110,23 @@ private class DateView : View {
|
||||
if indicatorCount > 0 {
|
||||
let width = (indicatorCount * 8) + (Int(VDSLayout.space1X) * (indicatorCount - 1))
|
||||
stackView.widthAnchor.constraint(equalToConstant: CGFloat(width)).activate()
|
||||
for x in (0...(dateIndicators.count-1)) {
|
||||
if (self.numberLabel.text == self.getDay(with: dateIndicators[x].date)) {
|
||||
for x in (0...(indicators.count-1)) {
|
||||
if (self.numberLabel.text == self.getDay(with: indicators[x].date)) {
|
||||
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 {
|
||||
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
|
||||
if numberLabel.text == self.getDay(with: currentDate) {
|
||||
numberLabel.textStyle = .boldBodySmall
|
||||
if (numberLabel.text == self.getDay(with: currentDate)) {
|
||||
numberLabel.textStyle = hideDate ? .bodySmall : .boldBodySmall
|
||||
} else {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user