// // 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 = Color(uiColor: .mvmBlack) public var fontSize: CGFloat? public var fontName: String? public var fontStyle: LabelModel.FontStyle? public var textAlignment: NSTextAlignment = .left public var height: CGFloat? public var placeholder: String = "" public var placeholderFont: LabelModel.FontStyle = LabelModel.FontStyle.RegularMicro public var isEditable: Bool = true public var borderColor: Color? public var borderWidth: CGFloat = 0 public var showsPlaceholder: Bool = true //-------------------------------------------------- // MARK: - Keys //-------------------------------------------------- private enum CodingKeys: String, CodingKey { case moleculeName case backgroundColor case text case accessibilityText case textColor case fontStyle case fontSize case fontName case textAlignment case attributes case height case borderColor case borderWidth case placeholder case placeholderFont 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 } if let placeholder = try typeContainer.decodeIfPresent(String.self, forKey: .placeholder) { self.placeholder = placeholder } if let placeholderFont = try typeContainer.decodeIfPresent(LabelModel.FontStyle.self, forKey: .placeholderFont) { self.placeholderFont = placeholderFont } if let textAlignment = try typeContainer.decodeIfPresent(NSTextAlignment.self, forKey: .textAlignment) { self.textAlignment = textAlignment } if let textColor = try typeContainer.decodeIfPresent(Color.self, forKey: .textColor) { self.textColor = textColor } if let isEditable = try typeContainer.decodeIfPresent(Bool.self, forKey: .isEditable) { self.isEditable = isEditable } if let borderWidth = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .borderWidth) { self.borderWidth = borderWidth } borderColor = try typeContainer.decodeIfPresent(Color.self, forKey: .borderColor) accessibilityText = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityText) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) fontSize = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .accessibilityText) fontName = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityText) fontStyle = try typeContainer.decodeIfPresent(LabelModel.FontStyle.self, forKey: .fontStyle) height = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .height) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encodeIfPresent(moleculeName, forKey: .moleculeName) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encodeIfPresent(accessibilityText, forKey: .accessibilityText) try container.encodeIfPresent(textColor, forKey: .textColor) try container.encodeIfPresent(fontStyle, forKey: .fontStyle) try container.encodeIfPresent(height, forKey: .height) try container.encodeIfPresent(borderColor, forKey: .borderColor) try container.encodeIfPresent(fontSize, forKey: .fontSize) try container.encodeIfPresent(fontName, forKey: .fontName) try container.encode(text, forKey: .text) try container.encode(placeholder, forKey: .placeholder) try container.encode(placeholderFont, forKey: .placeholderFont) try container.encode(textAlignment, forKey: .textAlignment) try container.encode(isEditable, forKey: .isEditable) try container.encode(borderWidth, forKey: .borderWidth) } }