diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index b47d64d3..1c561bdd 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -305,6 +305,7 @@ D2E2A99823D8D63C000B42E6 /* ActionDetailWithImageModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2E2A99723D8D63C000B42E6 /* ActionDetailWithImageModel.swift */; }; D2E2A99A23D8D6B4000B42E6 /* HeadlineBodyButtonModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2E2A99923D8D6B4000B42E6 /* HeadlineBodyButtonModel.swift */; }; D2E2A99C23D8D975000B42E6 /* ImageHeadlineBodyModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2E2A99B23D8D975000B42E6 /* ImageHeadlineBodyModel.swift */; }; + D2E2A99D23DA3217000B42E6 /* UIStackViewAlignment+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A209CD223A7E2810068F8B0 /* UIStackViewAlignment+Extension.swift */; }; D2FB151B23A2B65B00C20E10 /* MoleculeContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2FB151A23A2B65B00C20E10 /* MoleculeContainer.swift */; }; D2FB151D23A40F1500C20E10 /* MoleculeStackItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2FB151C23A40F1500C20E10 /* MoleculeStackItem.swift */; }; DB06250B2293456500B72DD3 /* LeftRightLabelView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB06250A2293456500B72DD3 /* LeftRightLabelView.swift */; }; @@ -1532,6 +1533,7 @@ D29DF2B421E7B76D003B2FB9 /* MFLoadingSpinner.m in Sources */, D260106323D0C05000764D80 /* StackItemModel.swift in Sources */, D2E2A99823D8D63C000B42E6 /* ActionDetailWithImageModel.swift in Sources */, + D2E2A99D23DA3217000B42E6 /* UIStackViewAlignment+Extension.swift in Sources */, 01EB369423609801006832FA /* HeadlineBodyModel.swift in Sources */, 0A21DB7F235DECC500C160A2 /* EntryField.swift in Sources */, D2C5001921F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.m in Sources */, diff --git a/MVMCoreUI/Atoms/Views/ProgressBarModel.swift b/MVMCoreUI/Atoms/Views/ProgressBarModel.swift index 2efa0403..dd53afac 100644 --- a/MVMCoreUI/Atoms/Views/ProgressBarModel.swift +++ b/MVMCoreUI/Atoms/Views/ProgressBarModel.swift @@ -9,7 +9,7 @@ import Foundation @objcMembers public class ProgressBarModel: MoleculeModelProtocol { - public static var identifier: String = "progressbar" + public static var identifier: String = "progressBar" @Percent public var percent: CGFloat public var progressColor: Color = Color(uiColor: .mfCerulean()) public var backgroundColor: Color? = Color(uiColor: .mfLightSilver()) diff --git a/MVMCoreUI/BaseClasses/Button.swift b/MVMCoreUI/BaseClasses/Button.swift index 0c5d4bec..0a382705 100644 --- a/MVMCoreUI/BaseClasses/Button.swift +++ b/MVMCoreUI/BaseClasses/Button.swift @@ -12,8 +12,8 @@ public typealias ButtonAction = (Button) -> () //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- - public var model: MoleculeModelProtocol? - public var actionModel: ActionModelProtocol? + open var model: MoleculeModelProtocol? + open var actionModel: ActionModelProtocol? private var initialSetupPerformed = false @@ -23,7 +23,7 @@ public typealias ButtonAction = (Button) -> () // MARK: - Delegate //-------------------------------------------------- - public weak var buttonDelegate: ButtonDelegateProtocol? + open weak var buttonDelegate: ButtonDelegateProtocol? //-------------------------------------------------- // MARK: - Initializers @@ -48,6 +48,7 @@ public typealias ButtonAction = (Button) -> () // MARK: - Setup //-------------------------------------------------- + /// Required to be called any init. Ensures setupView() only gets called once public func initialSetup() { if !initialSetupPerformed { @@ -60,16 +61,17 @@ public typealias ButtonAction = (Button) -> () // MARK: - Methods //-------------------------------------------------- - public func addActionBlock( event: Event, _ buttonBlock: @escaping ButtonAction) { + /// Adds a block to be performed for the given event. + open func addActionBlock(event: Event, _ buttonBlock: @escaping ButtonAction) { self.buttonAction = buttonBlock addTarget(self, action: #selector(callActionBlock(_:)), for: event) } - func callActionBlock(_ sender: Button) { + @objc private func callActionBlock(_ sender: Button) { buttonAction?(self) } - public func set(with actionModel: ActionModelProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { + open func set(with actionModel: ActionModelProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { self.actionModel = actionModel buttonDelegate = delegateObject?.buttonDelegate @@ -104,14 +106,13 @@ public typealias ButtonAction = (Button) -> () } } - // MARK: - MVMCoreViewProtocol extension Button: MVMCoreViewProtocol { - public func updateView(_ size: CGFloat) {} + open func updateView(_ size: CGFloat) {} /// Will be called only once. - public func setupView() { + open func setupView() { translatesAutoresizingMaskIntoConstraints = false insetsLayoutMarginsFromSafeArea = false titleLabel?.numberOfLines = 0 @@ -121,7 +122,7 @@ extension Button: MVMCoreViewProtocol { // MARK: - MVMCoreUIMoleculeViewProtocol extension Button: MVMCoreUIMoleculeViewProtocol { - public func reset() { + open func reset() { backgroundColor = .clear } } diff --git a/MVMCoreUI/BaseClasses/Control.swift b/MVMCoreUI/BaseClasses/Control.swift index ed1c1874..d73e0fef 100644 --- a/MVMCoreUI/BaseClasses/Control.swift +++ b/MVMCoreUI/BaseClasses/Control.swift @@ -13,7 +13,7 @@ import UIKit // MARK: - Properties //-------------------------------------------------- open var json: [AnyHashable: Any]? - public var model: MoleculeModelProtocol? + open var model: MoleculeModelProtocol? private var initialSetupPerformed = false @@ -78,10 +78,10 @@ extension Control: AppleGuidelinesProtocol { // MARK: - MVMCoreViewProtocol extension Control: MVMCoreViewProtocol { - public func updateView(_ size: CGFloat) {} + open func updateView(_ size: CGFloat) {} /// Will be called only once. - public func setupView() { + open func setupView() { translatesAutoresizingMaskIntoConstraints = false insetsLayoutMarginsFromSafeArea = false } @@ -97,7 +97,7 @@ extension Control: MVMCoreUIMoleculeViewProtocol { } } - public func reset() { + open func reset() { backgroundColor = .clear } } diff --git a/MVMCoreUI/Utility/UIStackViewAlignment+Extension.swift b/MVMCoreUI/Utility/UIStackViewAlignment+Extension.swift index 18afca83..b2c4b82b 100644 --- a/MVMCoreUI/Utility/UIStackViewAlignment+Extension.swift +++ b/MVMCoreUI/Utility/UIStackViewAlignment+Extension.swift @@ -30,6 +30,11 @@ import Foundation try container.encode(alignment.rawValueString, forKey: .alignment) } */ + +enum AlignmentError: Error { + case notAnAlignment +} + extension UIStackView.Alignment: RawRepresentable { init?(rawValue: String) { @@ -70,3 +75,19 @@ extension UIStackView.Alignment: RawRepresentable { } } } + +extension UIStackView.Alignment: Codable { + public init(from decoder: Decoder) throws { + let typeContainer = try decoder.singleValueContainer() + let string = try typeContainer.decode(String.self) + guard let alignment = UIStackView.Alignment(rawValue: string) else { + throw AlignmentError.notAnAlignment + } + self = alignment + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + try container.encode(rawValueString) + } +}