From 33ffbf91295bdf7a87b75b9b6ad17090dd66e83d Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 28 Apr 2020 13:51:03 -0400 Subject: [PATCH] adding comments and structure. code alignment. --- .../Atomic/Atoms/Buttons/ButtonModel.swift | 35 ++++++++++++++++++- .../MoleculeModelProtocol.swift | 6 ++++ .../BaseControllers/ViewController.swift | 10 +++--- .../Views/Container/Container.swift | 2 ++ 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift b/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift index abdc1242..22969196 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/ButtonModel.swift @@ -8,6 +8,7 @@ import UIKit + public enum ButtonStyle: String, Codable { case primary case secondary @@ -19,8 +20,13 @@ public enum ButtonSize: String, Codable { } public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWatcherFieldProtocol { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + public static var identifier: String = "button" public var backgroundColor: Color? + public var isInverted: Bool = false public var title: String public var action: ActionModelProtocol public var enabled: Bool = true @@ -34,14 +40,22 @@ public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupW public var disabledBorderColor: Color? public var groupName: String = "" + //-------------------------------------------------- + // MARK: - Methods + //-------------------------------------------------- + public func setValidity(_ valid: Bool, group: FormGroupRule) { enabled = valid updateUI?() } /// Temporary binding mechanism for the view to update on enable changes. - public var updateUI: (() -> Void)? + public var updateUI: (() -> ())? + //-------------------------------------------------- + // MARK: - Initializers + //-------------------------------------------------- + public init(with title: String, action: ActionModelProtocol) { self.title = title self.action = action @@ -59,9 +73,14 @@ public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupW style = .primary } + //-------------------------------------------------- + // MARK: - Keys + //-------------------------------------------------- + private enum CodingKeys: String, CodingKey { case moleculeName case backgroundColor + case isInverted = "inverted" case title case action case enabled @@ -76,24 +95,37 @@ public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupW case groupName } + //-------------------------------------------------- + // MARK: - Codec + //-------------------------------------------------- + required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + + if let isInverted = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) { + self.isInverted = isInverted + } backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) title = try typeContainer.decode(String.self, forKey: .title) action = try typeContainer.decodeModel(codingKey: .action) + if let groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) { self.groupName = groupName } + if let style = try typeContainer.decodeIfPresent(ButtonStyle.self, forKey: .style) { self.style = style } + if let size = try typeContainer.decodeIfPresent(ButtonSize.self, forKey: .size) { self.size = size } + if let enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) { self.enabled = enabled } + fillColor = try typeContainer.decodeIfPresent(Color.self, forKey: .fillColor) textColor = try typeContainer.decodeIfPresent(Color.self, forKey: .textColor) borderColor = try typeContainer.decodeIfPresent(Color.self, forKey: .borderColor) @@ -106,6 +138,7 @@ public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupW var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) try container.encode(title, forKey: .title) + try container.encode(isInverted, forKey: .isInverted) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encodeModel(action, forKey: .action) try container.encode(enabled, forKey: .enabled) diff --git a/MVMCoreUI/Atomic/Protocols/ModelProtocols/MoleculeModelProtocol.swift b/MVMCoreUI/Atomic/Protocols/ModelProtocols/MoleculeModelProtocol.swift index dda19b35..f4d528f5 100644 --- a/MVMCoreUI/Atomic/Protocols/ModelProtocols/MoleculeModelProtocol.swift +++ b/MVMCoreUI/Atomic/Protocols/ModelProtocols/MoleculeModelProtocol.swift @@ -9,6 +9,7 @@ public enum MolecularError: Swift.Error { public protocol MoleculeModelProtocol: ModelProtocol { var moleculeName: String { get } + var isInverted: Bool { get set } var backgroundColor: Color? { get set } } @@ -25,4 +26,9 @@ public extension MoleculeModelProtocol { static var categoryCodingKey: String { return "moleculeName" } + + var isInverted: Bool { + get { return false } + set { } + } } diff --git a/MVMCoreUI/BaseControllers/ViewController.swift b/MVMCoreUI/BaseControllers/ViewController.swift index b12440a6..ade66d03 100644 --- a/MVMCoreUI/BaseControllers/ViewController.swift +++ b/MVMCoreUI/BaseControllers/ViewController.swift @@ -338,18 +338,18 @@ import UIKit } // MARK: - MVMCoreActionDelegateProtocol - open func handleOpenPage(for requestParameters: MVMCoreRequestParameters, actionInformation: [AnyHashable : Any]?, additionalData: [AnyHashable : Any]?) { + open func handleOpenPage(for requestParameters: MVMCoreRequestParameters, actionInformation: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?) { formValidator?.addFormParams(requestParameters: requestParameters) requestParameters.parentPageType = loadObject?.pageJSON?.optionalStringForKey("parentPageType") MVMCoreActionHandler.defaultHandleOpenPage(for: requestParameters, additionalData: additionalData, delegateObject: delegateObject()) } - open func logAction(withActionInformation actionInformation: [AnyHashable : Any]?, additionalData: [AnyHashable : Any]?) { + open func logAction(withActionInformation actionInformation: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?) { MVMCoreUILoggingHandler.shared()?.defaultLogAction(forController: self, actionInformation: actionInformation, additionalData: additionalData) } // MARK: - MoleculeDelegateProtocol - open func getModuleWithName(_ name: String?) -> [AnyHashable : Any]? { + open func getModuleWithName(_ name: String?) -> [AnyHashable: Any]? { guard let name = name else { return nil } return loadObject?.modulesJSON?.optionalDictionaryForKey(name) } @@ -390,7 +390,7 @@ import UIKit view.accessibilityElements = [pickerView, toolBar] } DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { - UIAccessibility.post(notification: UIAccessibility.Notification.layoutChanged, argument: textField.inputView) + UIAccessibility.post(notification: .layoutChanged, argument: textField.inputView) } } } @@ -399,7 +399,7 @@ import UIKit if textField === selectedField { if UIAccessibility.isVoiceOverRunning { view.accessibilityElements = nil - UIAccessibility.post(notification: UIAccessibility.Notification.layoutChanged, argument: textField) + UIAccessibility.post(notification: .layoutChanged, argument: textField) } selectedField = nil } diff --git a/MVMCoreUI/Containers/Views/Container/Container.swift b/MVMCoreUI/Containers/Views/Container/Container.swift index eb05cd21..8c95f110 100644 --- a/MVMCoreUI/Containers/Views/Container/Container.swift +++ b/MVMCoreUI/Containers/Views/Container/Container.swift @@ -9,8 +9,10 @@ import UIKit open class Container: View, ContainerProtocol { + public var view: UIView? let containerHelper = ContainerHelper() + var containerModel: ContainerModelProtocol? { get { return model as? ContainerModelProtocol } }