From d4c9753041d85f732c15a08289017153105a3bb3 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Wed, 8 Jan 2020 14:27:10 -0500 Subject: [PATCH] Percent --- MVMCoreUI/Atoms/Views/MultiProgress.swift | 2 +- MVMCoreUI/Atoms/Views/MultiProgressModel.swift | 10 +++++++--- MVMCoreUI/Atoms/Views/ProgressBarModel.swift | 16 +++++++--------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/MultiProgress.swift b/MVMCoreUI/Atoms/Views/MultiProgress.swift index bbe8ed76..aceaf775 100644 --- a/MVMCoreUI/Atoms/Views/MultiProgress.swift +++ b/MVMCoreUI/Atoms/Views/MultiProgress.swift @@ -27,7 +27,7 @@ import UIKit let view = UIView(frame: .zero) view.translatesAutoresizingMaskIntoConstraints = false addSubview(view) - view.backgroundColor = UIColor.mfGet(forHex: progressObject.color) + view.backgroundColor = progressObject.color.uiColor view.widthAnchor.constraint(equalTo: widthAnchor, multiplier: progressObject.progress).isActive = true view.leadingAnchor.constraint(equalTo: previous?.trailingAnchor ?? leadingAnchor).isActive = true previous = view diff --git a/MVMCoreUI/Atoms/Views/MultiProgressModel.swift b/MVMCoreUI/Atoms/Views/MultiProgressModel.swift index 9d1f11fd..98bb09cf 100644 --- a/MVMCoreUI/Atoms/Views/MultiProgressModel.swift +++ b/MVMCoreUI/Atoms/Views/MultiProgressModel.swift @@ -8,10 +8,14 @@ import Foundation - @objcMembers public class SingleProgressBarModel: Codable { - var progress: CGFloat - var color: String + @Percent var progress: CGFloat + var color: Color + + init(_ progress: CGFloat, color: Color) { + self.progress = progress + self.color = color + } } @objcMembers public class MultiProgressBarModel: MoleculeProtocol { diff --git a/MVMCoreUI/Atoms/Views/ProgressBarModel.swift b/MVMCoreUI/Atoms/Views/ProgressBarModel.swift index 47fabb6a..1e0bfeb1 100644 --- a/MVMCoreUI/Atoms/Views/ProgressBarModel.swift +++ b/MVMCoreUI/Atoms/Views/ProgressBarModel.swift @@ -10,13 +10,11 @@ import Foundation @objcMembers public class ProgressBarModel: MoleculeProtocol { public static var identifier: String = "progressbar" - - public var isRounded: Bool? - public var thickness: CGFloat? - ///from 0 to 100 - @Clamping(range: 0...100) public var percent: CGFloat + @Percent public var percent: CGFloat public var progressColor: Color = Color(uiColor: .mfCerulean()) public var backgroundColor: Color? = Color(uiColor: .mfLightSilver()) + public var isRounded: Bool? + public var thickness: CGFloat? enum CodingKeys: String, CodingKey { case moleculeName @@ -33,8 +31,6 @@ import Foundation required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - isRounded = try typeContainer.decodeIfPresent(Bool.self, forKey: .isRounded) - thickness = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .thickness) percent = try typeContainer.decode(CGFloat.self, forKey: .percent) if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .progressColor) { progressColor = color @@ -42,15 +38,17 @@ import Foundation if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) { backgroundColor = color } + isRounded = try typeContainer.decodeIfPresent(Bool.self, forKey: .isRounded) + thickness = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .thickness) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) - try container.encodeIfPresent(isRounded, forKey: .isRounded) - try container.encodeIfPresent(thickness, forKey: .thickness) try container.encode(percent, forKey: .percent) try container.encode(progressColor, forKey: .progressColor) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) + try container.encodeIfPresent(isRounded, forKey: .isRounded) + try container.encodeIfPresent(thickness, forKey: .thickness) } }