adding comments and structure. code alignment.
This commit is contained in:
parent
d03c20f1ee
commit
33ffbf9129
@ -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)
|
||||
|
||||
@ -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 { }
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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 }
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user