adding comments and structure. code alignment.

This commit is contained in:
Kevin G Christiano 2020-04-28 13:51:03 -04:00
parent d03c20f1ee
commit 33ffbf9129
4 changed files with 47 additions and 6 deletions

View File

@ -8,6 +8,7 @@
import UIKit import UIKit
public enum ButtonStyle: String, Codable { public enum ButtonStyle: String, Codable {
case primary case primary
case secondary case secondary
@ -19,8 +20,13 @@ public enum ButtonSize: String, Codable {
} }
public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWatcherFieldProtocol { public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWatcherFieldProtocol {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
public static var identifier: String = "button" public static var identifier: String = "button"
public var backgroundColor: Color? public var backgroundColor: Color?
public var isInverted: Bool = false
public var title: String public var title: String
public var action: ActionModelProtocol public var action: ActionModelProtocol
public var enabled: Bool = true public var enabled: Bool = true
@ -34,13 +40,21 @@ public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupW
public var disabledBorderColor: Color? public var disabledBorderColor: Color?
public var groupName: String = "" public var groupName: String = ""
//--------------------------------------------------
// MARK: - Methods
//--------------------------------------------------
public func setValidity(_ valid: Bool, group: FormGroupRule) { public func setValidity(_ valid: Bool, group: FormGroupRule) {
enabled = valid enabled = valid
updateUI?() updateUI?()
} }
/// Temporary binding mechanism for the view to update on enable changes. /// 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) { public init(with title: String, action: ActionModelProtocol) {
self.title = title self.title = title
@ -59,9 +73,14 @@ public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupW
style = .primary style = .primary
} }
//--------------------------------------------------
// MARK: - Keys
//--------------------------------------------------
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case moleculeName case moleculeName
case backgroundColor case backgroundColor
case isInverted = "inverted"
case title case title
case action case action
case enabled case enabled
@ -76,24 +95,37 @@ public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupW
case groupName case groupName
} }
//--------------------------------------------------
// MARK: - Codec
//--------------------------------------------------
required public init(from decoder: Decoder) throws { required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self) 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) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
title = try typeContainer.decode(String.self, forKey: .title) title = try typeContainer.decode(String.self, forKey: .title)
action = try typeContainer.decodeModel(codingKey: .action) action = try typeContainer.decodeModel(codingKey: .action)
if let groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) { if let groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) {
self.groupName = groupName self.groupName = groupName
} }
if let style = try typeContainer.decodeIfPresent(ButtonStyle.self, forKey: .style) { if let style = try typeContainer.decodeIfPresent(ButtonStyle.self, forKey: .style) {
self.style = style self.style = style
} }
if let size = try typeContainer.decodeIfPresent(ButtonSize.self, forKey: .size) { if let size = try typeContainer.decodeIfPresent(ButtonSize.self, forKey: .size) {
self.size = size self.size = size
} }
if let enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) { if let enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) {
self.enabled = enabled self.enabled = enabled
} }
fillColor = try typeContainer.decodeIfPresent(Color.self, forKey: .fillColor) fillColor = try typeContainer.decodeIfPresent(Color.self, forKey: .fillColor)
textColor = try typeContainer.decodeIfPresent(Color.self, forKey: .textColor) textColor = try typeContainer.decodeIfPresent(Color.self, forKey: .textColor)
borderColor = try typeContainer.decodeIfPresent(Color.self, forKey: .borderColor) 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) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(moleculeName, forKey: .moleculeName) try container.encode(moleculeName, forKey: .moleculeName)
try container.encode(title, forKey: .title) try container.encode(title, forKey: .title)
try container.encode(isInverted, forKey: .isInverted)
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
try container.encodeModel(action, forKey: .action) try container.encodeModel(action, forKey: .action)
try container.encode(enabled, forKey: .enabled) try container.encode(enabled, forKey: .enabled)

View File

@ -9,6 +9,7 @@ public enum MolecularError: Swift.Error {
public protocol MoleculeModelProtocol: ModelProtocol { public protocol MoleculeModelProtocol: ModelProtocol {
var moleculeName: String { get } var moleculeName: String { get }
var isInverted: Bool { get set }
var backgroundColor: Color? { get set } var backgroundColor: Color? { get set }
} }
@ -25,4 +26,9 @@ public extension MoleculeModelProtocol {
static var categoryCodingKey: String { static var categoryCodingKey: String {
return "moleculeName" return "moleculeName"
} }
var isInverted: Bool {
get { return false }
set { }
}
} }

View File

@ -338,18 +338,18 @@ import UIKit
} }
// MARK: - MVMCoreActionDelegateProtocol // 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) formValidator?.addFormParams(requestParameters: requestParameters)
requestParameters.parentPageType = loadObject?.pageJSON?.optionalStringForKey("parentPageType") requestParameters.parentPageType = loadObject?.pageJSON?.optionalStringForKey("parentPageType")
MVMCoreActionHandler.defaultHandleOpenPage(for: requestParameters, additionalData: additionalData, delegateObject: delegateObject()) 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) MVMCoreUILoggingHandler.shared()?.defaultLogAction(forController: self, actionInformation: actionInformation, additionalData: additionalData)
} }
// MARK: - MoleculeDelegateProtocol // MARK: - MoleculeDelegateProtocol
open func getModuleWithName(_ name: String?) -> [AnyHashable : Any]? { open func getModuleWithName(_ name: String?) -> [AnyHashable: Any]? {
guard let name = name else { return nil } guard let name = name else { return nil }
return loadObject?.modulesJSON?.optionalDictionaryForKey(name) return loadObject?.modulesJSON?.optionalDictionaryForKey(name)
} }
@ -390,7 +390,7 @@ import UIKit
view.accessibilityElements = [pickerView, toolBar] view.accessibilityElements = [pickerView, toolBar]
} }
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { 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 textField === selectedField {
if UIAccessibility.isVoiceOverRunning { if UIAccessibility.isVoiceOverRunning {
view.accessibilityElements = nil view.accessibilityElements = nil
UIAccessibility.post(notification: UIAccessibility.Notification.layoutChanged, argument: textField) UIAccessibility.post(notification: .layoutChanged, argument: textField)
} }
selectedField = nil selectedField = nil
} }

View File

@ -9,8 +9,10 @@
import UIKit import UIKit
open class Container: View, ContainerProtocol { open class Container: View, ContainerProtocol {
public var view: UIView? public var view: UIView?
let containerHelper = ContainerHelper() let containerHelper = ContainerHelper()
var containerModel: ContainerModelProtocol? { var containerModel: ContainerModelProtocol? {
get { return model as? ContainerModelProtocol } get { return model as? ContainerModelProtocol }
} }