// // TextViewModel.swift // MVMCoreUI // // Created by Kevin Christiano on 4/2/20. // Copyright © 2020 Verizon Wireless. All rights reserved. // import Foundation open class TextViewModel: MoleculeModelProtocol { //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- public static var identifier: String = "textView" public var backgroundColor: Color? public var text: String = "" public var accessibilityText: String? public var textColor: Color? public var fontStyle: LabelModel.FontStyle? public var textAlignment: NSTextAlignment? public var height: CGFloat? public var placeholder: String? public var isEditable: Bool = true //-------------------------------------------------- // MARK: - Keys //-------------------------------------------------- private enum CodingKeys: String, CodingKey { case moleculeName case text case accessibilityText case textColor case backgroundColor case fontStyle case fontName case fontSize case textAlignment case attributes case height case placeholder case isEditable } //-------------------------------------------------- // MARK: - Initializer //-------------------------------------------------- public init(text: String) { self.text = text } //-------------------------------------------------- // MARK: - Codec //-------------------------------------------------- required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) if let text = try typeContainer.decodeIfPresent(String.self, forKey: .text) { self.text = text } placeholder = try typeContainer.decodeIfPresent(String.self, forKey: .text) accessibilityText = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityText) textColor = try typeContainer.decodeIfPresent(Color.self, forKey: .textColor) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) fontStyle = try typeContainer.decodeIfPresent(LabelModel.FontStyle.self, forKey: .fontStyle) textAlignment = try typeContainer.decodeIfPresent(NSTextAlignment.self, forKey: .textAlignment) height = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .height) if let isEditable = try typeContainer.decodeIfPresent(Bool.self, forKey: .isEditable) { self.isEditable = isEditable } } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encodeIfPresent(moleculeName, forKey: .moleculeName) try container.encode(text, forKey: .text) try container.encodeIfPresent(accessibilityText, forKey: .accessibilityText) try container.encodeIfPresent(textColor, forKey: .textColor) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encodeIfPresent(fontStyle, forKey: .fontStyle) try container.encodeIfPresent(textAlignment, forKey: .textAlignment) try container.encodeIfPresent(height, forKey: .height) try container.encodeIfPresent(isEditable, forKey: .isEditable) } }