From a8dc76e3e5a1831b62b58500eb8205c75ec2e2ac Mon Sep 17 00:00:00 2001 From: Rebecca Antonelli Date: Mon, 10 Apr 2023 10:50:13 -0500 Subject: [PATCH] badge updates --- MVMCoreUI/Atomic/Atoms/Views/Badge.swift | 37 ++++++++++++++++--- MVMCoreUI/Atomic/Atoms/Views/BadgeModel.swift | 16 +++++--- 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Badge.swift b/MVMCoreUI/Atomic/Atoms/Views/Badge.swift index 8ec875c7..7d6110af 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Badge.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Badge.swift @@ -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() +// } } diff --git a/MVMCoreUI/Atomic/Atoms/Views/BadgeModel.swift b/MVMCoreUI/Atomic/Atoms/Views/BadgeModel.swift index 9aa22cd5..5a5098b0 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/BadgeModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/BadgeModel.swift @@ -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 {