badge updates

This commit is contained in:
Rebecca Antonelli 2023-04-10 10:50:13 -05:00
parent 5a842581c2
commit a8dc76e3e5
2 changed files with 42 additions and 11 deletions

View File

@ -29,22 +29,47 @@ open class Badge: VDS.Badge, VDSMoleculeViewProtocol {
// public convenience required init() {
// self.init(frame: .zero)
// }
public required init() {
super.init()
}
required public init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
//--------------------------------------------------
// MARK: - Public
//--------------------------------------------------
open func set(){
maxWidth = viewModel.maxWidth
numberOfLines = viewModel.numberOfLines ?? 3
fillColor = viewModel.fillColor
surface = viewModel.surface ?? .light
}
public func viewModelDidUpdate() {
// backgroundColor = viewModel.backgroundColor
// maxWidth = viewModel.maxWidth
// numberOfLines = viewModel.numberOfLines
// fillColor = viewModel.fillColor
// surface = viewModel.surface
//
// backgroundColor = viewModel.backgroundColor
maxWidth = viewModel.maxWidth
numberOfLines = viewModel.numberOfLines ?? 3
fillColor = viewModel.fillColor
surface = viewModel.surface ?? .light
}
public func updateView(_ size: CGFloat) {
}
// open override func setupView() {
// super.setupView()
// backgroundColor = .clear
// widthConstraint = widthAnchor.constraint(equalToConstant: 30)
// widthConstraint?.isActive = true
// heightConstraint = heightAnchor.constraint(equalTo: widthAnchor, multiplier: 1)
// heightConstraint?.isActive = true
// isAccessibilityElement = true
// updateAccessibilityLabel()
// }
}

View File

@ -21,19 +21,25 @@ open class BadgeModel: MoleculeModelProtocol {
public var numberOfLines: Int?
public var fillColor = Badge.FillColor.red
public var surface: Surface?
public var text: String = ""
private enum CodingKeys: String, CodingKey {
case text, fillColor, surface, numberOfLines, maxWidth
}
// public convenience init() {
// self.init()
// }
required public convenience init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let text = try container.decode(String.self, forKey: .text)
let fillColor = try container.decodeIfPresent(Badge.FillColor.self, forKey: .fillColor) ?? .red
let surface = try container.decodeIfPresent(Surface.self, forKey: .surface) ?? .light
let numberOfLines = try container.decodeIfPresent(Int.self, forKey: .numberOfLines) ?? 0
let maxWidth = try container.decodeIfPresent(CGFloat.self, forKey: .maxWidth)
self.init()
self.text = try container.decode(String.self, forKey: .text)
self.fillColor = try container.decodeIfPresent(Badge.FillColor.self, forKey: .fillColor) ?? .red
self.surface = try container.decodeIfPresent(Surface.self, forKey: .surface) ?? .light
self.numberOfLines = try container.decodeIfPresent(Int.self, forKey: .numberOfLines) ?? 1
self.maxWidth = try container.decodeIfPresent(CGFloat.self, forKey: .maxWidth)
}
public func encode(to encoder: Encoder) throws {